/****************************************************************************
 *
 *  ALi (Shanghai) Corporation, All Rights Reserved. 2008 Copyright (C)
 *
 *  File: media_control.c
 *
 *  Description: .
 *
 *  History:
 *  Date            Author  		Version  Comment
 *  ====            ======  		=======  =======
 *  1.  2009.01.09  Sharon Zhang				edit for mediaplayer 3.0
 *
 ****************************************************************************/
#include <sys_config.h>

#ifdef USB_MP_SUPPORT
#include <types.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>
#include <api/libmp/media_player_api.h>
#include <api/libmp/pe.h>
#include <api/libfs2/statvfs.h>
#ifndef NEW_DEMO_FRAME
#include <api/libpub29/lib_hde.h>
#else
#include <api/libpub/lib_hde.h>
#endif

#include <api/libosd/osd_lib.h>
#include <hld/pan/pan_dev.h>
#include <hld/decv/decv.h>

#include "osdobjs_def.h"
#include "images.id"
#include "string.id"
#include "osd_config.h"

#include "control.h"
#include "menus_root.h"
#include "win_com.h"
#include "win_com_popup.h"
#include "win_com_list.h"
#include "win_media.h"
#include "copper_common/com_api.h"
#include <api/libmp/mp_subtitle_api.h>
#include <ali2dto3d/ALi_pic_2dto3d.h>

#ifdef ES_PLAYER_TEST
#include <hld/decv/decv_media_player.h>
#include <hld/deca/deca.h>
#include <api/libmp/es_player_api.h>
#include <api/libfs2/stat.h>
#include <api/libfs2/dirent.h>
#include <api/libfs2/statvfs.h>
#include <api/libfs2/unistd.h>
#include <api/libfs2/stdio.h>
#endif

extern font_subt_t *font_array_1bit_subt[];

#ifdef _INVW_JUICE  //v0.1.4
// An alternative media player callback handler which may optionally be set
// to handle events outside of the native player
static mp_callback_func mp_alternative_cb = 0;
#endif
///////////////////////////////////////
// start of title & help UI definition
///////////////////////////////////////
extern CONTAINER  usb_title_con;
extern BITMAP 	  usb_title_bmp1;
extern TEXT_FIELD usb_title_txt1;
extern BITMAP 	  usb_title_bmp2;
extern TEXT_FIELD usb_title_txt2;
extern BITMAP 	  usb_title_bmp3;
extern TEXT_FIELD usb_title_txt3;
extern BITMAP 	  usb_title_bmp4;
extern TEXT_FIELD usb_title_txt4;
extern BITMAP 	  usb_title_line1;
extern BITMAP 	  usb_title_line2;
extern BITMAP 	  usb_title_line3;

extern CONTAINER  usb_help_win;
extern CONTAINER  usb_help_con;
extern BITMAP 	  usb_help1_btn1;
extern BITMAP 	  usb_help1_btn2;
extern BITMAP 	  usb_help1_btn3;
extern BITMAP 	  usb_help1_btn4;
extern BITMAP 	  usb_help1_btn5;
extern TEXT_FIELD usb_help1_txt1;
extern TEXT_FIELD usb_help1_txt2;
extern TEXT_FIELD usb_help1_txt3;
extern TEXT_FIELD usb_help1_txt4;
extern TEXT_FIELD usb_help1_txt5;

extern BITMAP	  usb_help2_btn1;
extern BITMAP	  usb_help2_btn2;
extern BITMAP 	  usb_help2_btn3;
extern BITMAP 	  usb_help2_btn4;
extern BITMAP 	  usb_help2_btn5;
extern TEXT_FIELD usb_help2_txt1;
extern TEXT_FIELD usb_help2_txt2;
extern TEXT_FIELD usb_help2_txt3;
extern TEXT_FIELD usb_help2_txt4;
extern TEXT_FIELD usb_help2_txt5;

#if Maker_GUI_ON
#define TITLE_SH_IDX  WSTL_WIN_TITLE_YJ
#else
#define TITLE_SH_IDX  WSTL_WIN_TITLE_01_HD
#endif
#define TITLE_ICON1_SH	WSTL_MIX_BMP_HD
#define TITLE_TXT1_SH	WSTL_MIXBACK_IDX_01_8BIT//sharon WSTL_MP_TEXT_01_HD
#define TITLE_ICON2_SH	WSTL_MIX_BMP_HD
#define TITLE_TXT2_SH	WSTL_MIXBACK_IDX_04_8BIT//sharon WSTL_MP_TEXT_02_HD
#define TITLE_TXT2_GRY	WSTL_MIXBACK_IDX_07_8BIT//sharon WSTL_MP_TEXT_02_HD

#define HLP_WIN_SH_IDX  WSTL_MP_WIN_BOTTOM_HD
#define HLP_CON_SH_IDX  WSTL_MP_HELP_HD

#ifndef SD_UI
#if Maker_GUI_TEST
#define TITLE_L		74
#define TITLE_T		5//FL_W_T
#define TITLE_W		866
#define TITLE_H		68
#define TITLE_GAP	210

#define TITLE_ICON_W		0//40//96
#define TITLE_ICON_H		0//40//64
#define TITLE_TXT_W		156
#define TITLE_TXT_H		40
#else
#define TITLE_L		74
#define TITLE_T		5//FL_W_T
#define TITLE_W		866
#define TITLE_H		68
#define TITLE_GAP	210


#define TITLE_ICON_W		56//40//96
#define TITLE_ICON_H		54//40//64
#define TITLE_TXT_W		100
#define TITLE_TXT_H		40
#endif

#define TITLE_ICON1_L		(TITLE_L+40)
#define TITLE_ICON1_T		(TITLE_T)
#define TITLE_TXT1_L		(TITLE_ICON1_L+TITLE_ICON_W)
#define TITLE_TXT1_T		(TITLE_ICON1_T+8)

#define TITLE_ICON2_L		(TITLE_ICON1_L+TITLE_GAP)//(TITLE_L+280)
#define TITLE_ICON2_T		(TITLE_T)
#define TITLE_TXT2_L		(TITLE_ICON2_L+TITLE_ICON_W)
#define TITLE_TXT2_T		(TITLE_ICON2_T+8)

#define TITLE_ICON3_L		(TITLE_ICON2_L+TITLE_GAP)//(TITLE_L+460)
#define TITLE_ICON3_T		(TITLE_T)
#define TITLE_TXT3_L		(TITLE_ICON3_L+TITLE_ICON_W)
#define TITLE_TXT3_T		(TITLE_ICON3_T+8)

#define TITLE_ICON4_L		(TITLE_ICON3_L+TITLE_GAP)//(TITLE_L+640)
#define TITLE_ICON4_T		(TITLE_T)
#define TITLE_TXT4_L		(TITLE_ICON4_L+TITLE_ICON_W)
#define TITLE_TXT4_T		(TITLE_ICON4_T+8)

#define TITLE_LINE_L		(TITLE_L+TITLE_GAP)
#define TITLE_LINE_T		TITLE_T
#define TITLE_LINE_W		8
#define TITLE_LINE_H		54

#define HLPWIN_L TITLE_L
#define HLPWIN_T (TITLE_T+TITLE_H+440)//(LSTCON_T + LSTCON_H)
#define HLPWIN_W TITLE_W
#define HLPWIN_H 100

#define HLPCON_L (HLPWIN_L+14)
#define HLPCON_T (HLPWIN_T+6)//(LSTCON_T + LSTCON_H)
#define HLPCON_W (HLPWIN_W-28)
#define HLPCON_H (HLPWIN_H-20)

#define HELP_T1 (HLPCON_T+4)
#define HELP_H 36
#define HELP_T2 (HELP_T1+HELP_H)
#define HELP_ICON_W 36
#define HELP_TXT_W 	130
#define HELP_L (HLPCON_L+6)
#else
#define TITLE_L		17
#define TITLE_T		12//FL_W_T
#define TITLE_W		570
#define TITLE_H		45
#define TITLE_GAP	110

#define TITLE_ICON_W		43//40//96
#define TITLE_ICON_H		43//40//64
#define TITLE_TXT_W		100
#define TITLE_TXT_H		32

#define TITLE_ICON1_L		(TITLE_L+20)
#define TITLE_ICON1_T		(TITLE_T)
#define TITLE_TXT1_L		(TITLE_ICON1_L+TITLE_ICON_W)
#define TITLE_TXT1_T		(TITLE_ICON1_T+8)

#define TITLE_ICON2_L		(TITLE_ICON1_L+TITLE_GAP)//(TITLE_L+280)
#define TITLE_ICON2_T		(TITLE_T)
#define TITLE_TXT2_L		(TITLE_ICON2_L+TITLE_ICON_W)
#define TITLE_TXT2_T		(TITLE_ICON2_T+8)

#define TITLE_ICON3_L		(TITLE_ICON2_L+TITLE_GAP)//(TITLE_L+460)
#define TITLE_ICON3_T		(TITLE_T)
#define TITLE_TXT3_L		(TITLE_ICON3_L+TITLE_ICON_W)
#define TITLE_TXT3_T		(TITLE_ICON3_T+8)

#define TITLE_ICON4_L		(TITLE_ICON3_L+TITLE_GAP)//(TITLE_L+640)
#define TITLE_ICON4_T		(TITLE_T)
#define TITLE_TXT4_L		(TITLE_ICON4_L+TITLE_ICON_W)
#define TITLE_TXT4_T		(TITLE_ICON4_T+8)

#define TITLE_LINE_L		(TITLE_L+TITLE_GAP)
#define TITLE_LINE_T		TITLE_T
#define TITLE_LINE_W		0
#define TITLE_LINE_H		54

#define HLPWIN_L TITLE_L
#define HLPWIN_T (TITLE_T+TITLE_H+350)//(LSTCON_T + LSTCON_H)
#define HLPWIN_W TITLE_W
#define HLPWIN_H 75

#define HLPCON_L (HLPWIN_L+10)
#define HLPCON_T (HLPWIN_T+6)//(LSTCON_T + LSTCON_H)
#define HLPCON_W (HLPWIN_W-20)
#define HLPCON_H 58//(HLPWIN_H-20)

#define HELP_T1 (HLPCON_T+4)
#define HELP_H 24//36
#define HELP_T2 (HELP_T1+HELP_H)
#define HELP_ICON_W 26
#define HELP_TXT_W 	81
#define HELP_L (HLPCON_L+6)
#endif

struct mp_title_tab_resource
{
	UINT16	bmp_id;
	UINT16	str_id;
};

struct mp_help_item1_resource
{
	UINT16	bmp_id;
	UINT16	str_id;
};

struct mp_help_item2_resource
{
	char*	icon_txt;
	UINT16	str_id;
};

#define LDEF_TITLE_CON(root, varCon,nxtObj,l,t,w,h,conobj,focusID,allHilite)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,   \
    NULL,NULL,  \
    conobj, focusID,allHilite)

#define LDET_TITLE_BMP(root,varBmp,nxtObj,l,t,w,h,sh,icon)	\
  DEF_BITMAP(varBmp,&root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, sh,sh,sh,sh,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER,0,0,icon)

#if Maker_GUI_TEST
#define LDEF_TITLE_TXT(root,varTxt,nxtObj,l,t,w,h,sh,resID,str)		\
    DEF_TEXTFIELD(varTxt,&root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, sh,sh,sh,sh,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,resID,str)
#else
#define LDEF_TITLE_TXT(root,varTxt,nxtObj,l,t,w,h,sh,resID,str)		\
    DEF_TEXTFIELD(varTxt,&root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, sh,sh,sh,sh,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,resID,str)
#endif    

#define LDEF_HLP_WIN(root, varCon,nxtObj,l,t,w,h,conobj)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, HLP_WIN_SH_IDX,HLP_WIN_SH_IDX,HLP_WIN_SH_IDX,HLP_WIN_SH_IDX,   \
    NULL,NULL,  \
    conobj, 1,1)

#define LDEF_HLP_CON(root, varCon,nxtObj,l,t,w,h,conobj)		\
    DEF_CONTAINER(varCon,&root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, HLP_CON_SH_IDX,HLP_CON_SH_IDX,HLP_CON_SH_IDX,HLP_CON_SH_IDX,   \
    NULL,NULL,  \
    conobj, 1,1)

#define LDET_HLP_BMP(root,varBmp,nxtObj,l,t,w,h)	\
  DEF_BITMAP(varBmp,&root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, WSTL_WIN_EPG_HELP_HD,WSTL_WIN_EPG_HELP_HD,WSTL_WIN_EPG_HELP_HD,WSTL_WIN_EPG_HELP_HD,   \
    NULL,NULL,  \
	C_ALIGN_CENTER| C_ALIGN_VCENTER, 0, 0,0)

#define LDEF_HLP_TXT(root,varTxt,nxtObj,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,&root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, WSTL_WIN_EPG_HELP_HD,WSTL_WIN_EPG_HELP_HD,WSTL_WIN_EPG_HELP_HD,WSTL_MP_HELP_GRY,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,resID,str)

LDEF_TITLE_CON(NULL, usb_title_con, NULL,TITLE_L,TITLE_T,TITLE_W,TITLE_H,&usb_title_bmp1,1,1)
#if Maker_GUI_TEST
LDET_TITLE_BMP(usb_title_con, usb_title_bmp1, &usb_title_txt1, 	TITLE_ICON1_L, TITLE_ICON1_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON1_SH, NULL)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt1, &usb_title_bmp2, 	TITLE_TXT1_L,  TITLE_TXT1_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT1_SH,  RS_MP_MUSIC,NULL)
LDET_TITLE_BMP(usb_title_con, usb_title_bmp2, &usb_title_txt2, 	TITLE_ICON2_L, TITLE_ICON2_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON2_SH, NULL)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt2, &usb_title_bmp3, 	TITLE_TXT2_L,  TITLE_TXT2_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT2_SH,  RS_MP_IMAGE,NULL)
LDET_TITLE_BMP(usb_title_con, usb_title_bmp3, &usb_title_txt3, 	TITLE_ICON3_L, TITLE_ICON3_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON2_SH, NULL)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt3, &usb_title_bmp4, 	TITLE_TXT3_L,  TITLE_TXT3_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT2_SH,  RS_PVR,NULL)
LDET_TITLE_BMP(usb_title_con, usb_title_bmp4, &usb_title_txt4, 	TITLE_ICON4_L, TITLE_ICON4_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON2_SH, NULL)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt4, &usb_title_line1, 			TITLE_TXT4_L,  TITLE_TXT4_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT2_SH,  RS_MP_VIDEO,NULL)
#else
LDET_TITLE_BMP(usb_title_con, usb_title_bmp1, &usb_title_txt1, 	TITLE_ICON1_L, TITLE_ICON1_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON1_SH, IM_MEDIAPLAY_TOPBG_ICON_MUSIC)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt1, &usb_title_bmp2, 	TITLE_TXT1_L,  TITLE_TXT1_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT1_SH,  RS_MP_MUSIC,NULL)
LDET_TITLE_BMP(usb_title_con, usb_title_bmp2, &usb_title_txt2, 	TITLE_ICON2_L, TITLE_ICON2_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON2_SH, IM_MEDIAPLAY_TOPBG_ICON_PHOTO_S)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt2, &usb_title_bmp3, 	TITLE_TXT2_L,  TITLE_TXT2_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT2_SH,  RS_MP_IMAGE,NULL)
LDET_TITLE_BMP(usb_title_con, usb_title_bmp3, &usb_title_txt3, 	TITLE_ICON3_L, TITLE_ICON3_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON2_SH, IM_MEDIAPLAY_TOPBG_ICON_RECORD_S)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt3, &usb_title_bmp4, 	TITLE_TXT3_L,  TITLE_TXT3_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT2_SH,  RS_PVR,NULL)
LDET_TITLE_BMP(usb_title_con, usb_title_bmp4, &usb_title_txt4, 	TITLE_ICON4_L, TITLE_ICON4_T, TITLE_ICON_W, TITLE_ICON_H, TITLE_ICON2_SH, IM_MEDIAPLAY_TOPBG_ICON_VIDEO_S)
LDEF_TITLE_TXT(usb_title_con, usb_title_txt4, &usb_title_line1, 			TITLE_TXT4_L,  TITLE_TXT4_T,  TITLE_TXT_W,  TITLE_TXT_H,  TITLE_TXT2_SH,  RS_MP_VIDEO,NULL)
#endif
LDET_TITLE_BMP(usb_title_con, usb_title_line1, &usb_title_line2, 	TITLE_LINE_L, TITLE_LINE_T, TITLE_LINE_W, TITLE_LINE_H, TITLE_ICON1_SH, IM_MEDIAPLAY_TITLELINE_01)
LDET_TITLE_BMP(usb_title_con, usb_title_line2, &usb_title_line3, 	TITLE_LINE_L+TITLE_GAP, TITLE_LINE_T, TITLE_LINE_W, TITLE_LINE_H, TITLE_ICON1_SH, IM_MEDIAPLAY_TITLELINE_01)
LDET_TITLE_BMP(usb_title_con, usb_title_line3, NULL, 	TITLE_LINE_L+TITLE_GAP*2, TITLE_LINE_T, TITLE_LINE_W, TITLE_LINE_H, TITLE_ICON1_SH, IM_MEDIAPLAY_TITLELINE_01)

LDEF_HLP_WIN(NULL, usb_help_win,NULL,HLPWIN_L,HLPWIN_T,HLPWIN_W,HLPWIN_H,&usb_help_con)
LDEF_HLP_CON(usb_help_win, usb_help_con,NULL,HLPCON_L,HLPCON_T,HLPCON_W,HLPCON_H,&usb_help1_btn1)
LDET_HLP_BMP(usb_help_con, usb_help1_btn1, &usb_help1_txt1,	HELP_L, HELP_T1, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help1_txt1, &usb_help1_btn2,	HELP_L+HELP_ICON_W, HELP_T1, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
LDET_HLP_BMP(usb_help_con, usb_help1_btn2, &usb_help1_txt2,	HELP_L+1*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help1_txt2, &usb_help1_btn3,	HELP_L+HELP_ICON_W+1*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
LDET_HLP_BMP(usb_help_con, usb_help1_btn3, &usb_help1_txt3,	HELP_L+2*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help1_txt3, &usb_help1_btn4,	HELP_L+HELP_ICON_W+2*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
LDET_HLP_BMP(usb_help_con, usb_help1_btn4, &usb_help1_txt4,	HELP_L+3*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help1_txt4, &usb_help1_btn5,	HELP_L+HELP_ICON_W+3*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
LDET_HLP_BMP(usb_help_con, usb_help1_btn5, &usb_help1_txt5,	HELP_L+4*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help1_txt5, &usb_help2_btn1,	HELP_L+HELP_ICON_W+4*(HELP_ICON_W+HELP_TXT_W), HELP_T1, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)

LDET_HLP_BMP(usb_help_con, usb_help2_btn1, &usb_help2_txt1,	HELP_L, HELP_T2, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help2_txt1, &usb_help2_btn2,	HELP_L+HELP_ICON_W, HELP_T2, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
LDET_HLP_BMP(usb_help_con, usb_help2_btn2, &usb_help2_txt2,	HELP_L+1*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help2_txt2, &usb_help2_btn3,	HELP_L+HELP_ICON_W+1*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
LDET_HLP_BMP(usb_help_con, usb_help2_btn3, &usb_help2_txt3,	HELP_L+2*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help2_txt3, &usb_help2_btn4,	HELP_L+HELP_ICON_W+2*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
LDET_HLP_BMP(usb_help_con, usb_help2_btn4, &usb_help2_txt4,	HELP_L+3*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_ICON_W, HELP_H)
#ifndef SD_UI
LDEF_HLP_TXT(usb_help_con, usb_help2_txt4, &usb_help2_btn5,	HELP_L+HELP_ICON_W+3*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)
#else
LDEF_HLP_TXT(usb_help_con, usb_help2_txt4, &usb_help2_btn5,	HELP_L+HELP_ICON_W+3*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_TXT_W+5, HELP_H, RS_COMMON_OK,NULL)
#endif
LDET_HLP_BMP(usb_help_con, usb_help2_btn5, &usb_help2_txt5,	HELP_L+4*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_ICON_W, HELP_H)
LDEF_HLP_TXT(usb_help_con, usb_help2_txt5, NULL,			HELP_L+HELP_ICON_W+4*(HELP_ICON_W+HELP_TXT_W), HELP_T2, HELP_TXT_W, HELP_H, RS_COMMON_OK,NULL)


//filelist title tab define
struct mp_title_tab_resource title_tab[] =
{
#if((defined SUPPORT_CAS9 || defined FTA_ONLY || defined SUPPORT_VMX_STD || defined SUPPORT_VMX) && (!defined MEDIAPLAYER_SUPPORT))
	{0,		0},
    {0,		0},
    {0,		0},
    {IM_MEDIAPLAY_TOPBG_ICON_RECORD,		RS_PVR},

    {0,		0},
    {0,		0},
    {0,		0},
    {IM_MEDIAPLAY_TOPBG_ICON_RECORD_S,	RS_PVR},

    {0,	0},
    {0,	0},
    {0,	0},
    {IM_MEDIAPLAY_TOPBG_ICON_RECORD_GRAY,	RS_PVR},
#else
#if Maker_GUI_TEST
	{0,		RS_MP_MUSIC},
    {0,		RS_MP_IMAGE},
    {0,		RS_MP_VIDEO},
    {0,		RS_PVR},
    
    {0,		RS_MP_MUSIC},
    {0,		RS_MP_IMAGE},
    {0,		RS_MP_VIDEO},
    {0,	RS_PVR},
    
    {0,	RS_MP_MUSIC},
    {0,	RS_MP_IMAGE},
    {0,	RS_MP_VIDEO},
    {0,	RS_PVR},
#else
    {IM_MEDIAPLAY_TOPBG_ICON_MUSIC,		RS_MP_MUSIC},
    {IM_MEDIAPLAY_TOPBG_ICON_PHOTO,		RS_MP_IMAGE},
    {IM_MEDIAPLAY_TOPBG_ICON_VIDEO,		RS_MP_VIDEO},
    {IM_MEDIAPLAY_TOPBG_ICON_RECORD,		RS_PVR},

    {IM_MEDIAPLAY_TOPBG_ICON_MUSIC_S,		RS_MP_MUSIC},
    {IM_MEDIAPLAY_TOPBG_ICON_PHOTO_S,		RS_MP_IMAGE},
    {IM_MEDIAPLAY_TOPBG_ICON_VIDEO_S,		RS_MP_VIDEO},
    {IM_MEDIAPLAY_TOPBG_ICON_RECORD_S,	RS_PVR},

    {IM_MEDIAPLAY_TOPBG_ICON_MUSIC_GRAY,	RS_MP_MUSIC},
    {IM_MEDIAPLAY_TOPBG_ICON_PHOTO_GRAY,	RS_MP_IMAGE},
    {IM_MEDIAPLAY_TOPBG_ICON_VIDEO_GRAY,	RS_MP_VIDEO},
    {IM_MEDIAPLAY_TOPBG_ICON_RECORD_GRAY,	RS_PVR},
#endif
#endif    
};

#ifdef DLNA_DMP_SUPPORT
struct mp_title_tab_resource dlna_title_tab[] =
{
    {IM_MEDIAPLAY_TOPBG_ICON_VIDEO,		RS_DLNA_PLAY},
};
#endif
#define HELPCNT	5

BITMAP *pHelp1Btn_icons[] =
{
	&usb_help1_btn1,
	&usb_help1_btn2,
	&usb_help1_btn3,
	&usb_help1_btn4,
	&usb_help1_btn5,
};

TEXT_FIELD *pHelp1Txt_ids[] =
{
	&usb_help1_txt1,
	&usb_help1_txt2,
	&usb_help1_txt3,
	&usb_help1_txt4,
	&usb_help1_txt5,
};

BITMAP *pHelp2Btn_icons[] =
{
	&usb_help2_btn1,
	&usb_help2_btn2,
	&usb_help2_btn3,
	&usb_help2_btn4,
	&usb_help2_btn5,
};

TEXT_FIELD *pHelp2Txt_ids[] =
{
	&usb_help2_txt1,
	&usb_help2_txt2,
	&usb_help2_txt3,
	&usb_help2_txt4,
	&usb_help2_txt5,
};

////////////////////
//music help define
struct mp_help_item1_resource  music_help1[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
    {IM_FILELIST_NUMBERBUTTON1,     RS_MP_PLAY_LIST},
    {IM_FILELIST_NUMBERBUTTON2,     RS_FAV},
    {IM_FILELIST_NUMBERBUTTON3,		RS_MP_FAV_ALL},
#else
    {IM_EPG_COLORBUTTON_RED,       RS_MP_PLAY_LIST},
    {IM_EPG_COLORBUTTON_GREEN,     RS_FAV},
    {IM_EPG_COLORBUTTON_YELLOW,    RS_MP_FAV_ALL},
    {IM_EPG_COLORBUTTON_BLUE,      RS_HELP_EDIT},
    {IM_MEDIAPLAY_HELPBUTTON_I,    0},
#endif
};
#define MUSIC_HELP1_CNT	(sizeof(music_help1)/sizeof(struct mp_help_item1_resource))

struct mp_help_item1_resource  music_help2[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_EXIT,	RS_HELP_EXIT},
	{IM_FILELIST_NUMBERBUTTON4,		RS_HELP_EDIT},
    {IM_FILELIST_NUMBERBUTTON5,		RS_HELP_SORT},
    {IM_FILELIST_NUMBERBUTTON6,		RS_MP_REPEAT_MODE},
#else
    {IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
    {IM_MEDIAPLAY_HELPBUTTON_PIP,     RS_HELP_SORT},
    {IM_MEDIAPLAY_HELPBUTTON_AB,    	RS_MP_REPEAT_MODE},
    {IM_MEDIAPLAY_HELPBUTTON_EXIT,    RS_HELP_EXIT},
#endif    
};
#define MUSIC_HELP2_CNT	(sizeof(music_help2)/sizeof(struct mp_help_item1_resource))

////////////////////
//photo help define
struct mp_help_item1_resource  photo_help1[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
    {IM_FILELIST_NUMBERBUTTON1,		RS_MP_PLAY_LIST},
    {IM_FILELIST_NUMBERBUTTON2,		RS_FAV},
    {IM_FILELIST_NUMBERBUTTON3,		RS_MP_FAV_ALL},
#else
    {IM_EPG_COLORBUTTON_RED,       RS_MP_PLAY_LIST},
    {IM_EPG_COLORBUTTON_GREEN,     RS_FAV},
    {IM_EPG_COLORBUTTON_YELLOW,    RS_MP_FAV_ALL},
    {IM_EPG_COLORBUTTON_BLUE,      RS_HELP_EDIT},
    {IM_MEDIAPLAY_HELPBUTTON_I,    0},
#endif
};
#define PHOTO_HELP1_CNT	(sizeof(photo_help1)/sizeof(struct mp_help_item1_resource))

struct mp_help_item1_resource  photo_help2[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_EXIT,	RS_HELP_EXIT},
	{IM_FILELIST_NUMBERBUTTON4,		RS_HELP_EDIT},
    {IM_FILELIST_NUMBERBUTTON5,		RS_HELP_SORT},
    {IM_FILELIST_NUMBERBUTTON6,		RS_GAME_SETUP},
    {IM_FILELIST_NUMBERBUTTON7,		RS_MP_HELP_MULTI_VIEW},
#else
    {IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
    {IM_MEDIAPLAY_HELPBUTTON_PIP,     RS_HELP_SORT},
    {IM_MEDIAPLAY_HELPBUTTON_AB,    	RS_GAME_SETUP},
    {IM_MEDIAPLAY_HELPBUTTON_MP,		RS_MP_HELP_MULTI_VIEW},
    {IM_MEDIAPLAY_HELPBUTTON_EXIT,    RS_HELP_EXIT},
#endif    
};
#define PHOTO_HELP2_CNT	(sizeof(photo_help2)/sizeof(struct mp_help_item1_resource))

////////////////////
//video help define
struct mp_help_item1_resource  video_help1[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
	{IM_FILELIST_NUMBERBUTTON1,		RS_HELP_EDIT},
	{IM_FILELIST_NUMBERBUTTON2,		RS_HELP_SORT},
	{IM_FILELIST_NUMBERBUTTON3,		RS_MP_REPEAT_MODE},
#else
//    {IM_EPG_COLORBUTTON_RED,       RS_MP_PLAY_LIST},
//    {IM_EPG_COLORBUTTON_GREEN,     RS_FAV},
//    {IM_EPG_COLORBUTTON_YELLOW,    RS_MP_FAV_ALL},
    {IM_EPG_COLORBUTTON_BLUE,      RS_HELP_EDIT},
    {IM_MEDIAPLAY_HELPBUTTON_I,    0},
#endif
};
#define VIDEO_HELP1_CNT	(sizeof(video_help1)/sizeof(struct mp_help_item1_resource))

struct mp_help_item1_resource  video_help2[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_EXIT,	RS_HELP_EXIT},
#else
    {IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
    {IM_MEDIAPLAY_HELPBUTTON_PIP,     RS_HELP_SORT},
    {IM_MEDIAPLAY_HELPBUTTON_EXIT,    RS_HELP_EXIT},
    {IM_MEDIAPLAY_HELPBUTTON_AB,    	RS_MP_REPEAT_MODE},
#endif
};
#define VIDEO_HELP2_CNT	(sizeof(video_help2)/sizeof(struct mp_help_item1_resource))

////////////////////
//record help define
struct mp_help_item1_resource  record_help1[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
	{IM_FILELIST_NUMBERBUTTON1,		RS_HELP_RENAME},
	{IM_FILELIST_NUMBERBUTTON2,		RS_SORT_LOCK},
	{IM_FILELIST_NUMBERBUTTON3,		RS_HELP_DELETE},
#else
    {IM_EPG_COLORBUTTON_RED,       RS_HELP_RENAME},
    {IM_EPG_COLORBUTTON_GREEN,     RS_SORT_LOCK},
    {IM_EPG_COLORBUTTON_YELLOW,    RS_HELP_DELETE},
//    {IM_EPG_COLORBUTTON_BLUE,      RS_DISEQC12_ADVANCE},
    {IM_MEDIAPLAY_HELPBUTTON_I,    0},
#endif
};

#define RECORD_HELP1_CNT	(sizeof(record_help1)/sizeof(struct mp_help_item1_resource))

struct mp_help_item1_resource  record_help2[] =
{
#if 1//ChengYu@20131001, change file list help icon
	{IM_MEDIAPLAY_HELPBUTTON_EXIT,	RS_HELP_EXIT},
#else
#if((!defined SUPPORT_CAS9)|| (defined MEDIAPLAYER_SUPPORT))
    {IM_MEDIAPLAY_HELPBUTTON_SWAP,	RS_MP_HELP_SWITCH},
#endif
//    {IM_MEDIAPLAY_HELPBUTTON_PIP,     RS_HELP_SORT},
    {IM_MEDIAPLAY_HELPBUTTON_EXIT,    RS_HELP_EXIT},
#endif
};
#define RECORD_HELP2_CNT	(sizeof(record_help2)/sizeof(struct mp_help_item1_resource))

#ifdef DLNA_DMP_SUPPORT
struct mp_help_item1_resource  dlna_help1[] =
{
    {IM_MEDIAPLAY_HELPBUTTON_AB,    	RS_MP_REPEAT_MODE},
    {IM_MEDIAPLAY_HELPBUTTON_EXIT,    RS_HELP_EXIT},
};
#define DLNA_HELP1_CNT	(sizeof(dlna_help1)/sizeof(struct mp_help_item1_resource))
#endif

///////////////////////////////
//music&photo edit help define
struct mp_help_item1_resource  edit_help[] =
{	//Martin@20150105
    {IM_EPG_COLORBTN_RED,       RS_HELP_RENAME},
    {IM_EPG_COLORBTN_GREEN,     RS_HELP_COPY},
    {IM_EPG_COLORBTN_YELLOW,    RS_HELP_DELETE},
    {IM_EPG_COLORBTN_BLUE,      RS_MP_HELP_MAKE_FOLDER},
    //{IM_MEDIAPLAY_HELPBUTTON_I,    0},
};

#define EDIT_HELP_CNT	(sizeof(edit_help)/sizeof(struct mp_help_item1_resource))

///////////////////////////////
//record advance help define
struct mp_help_item1_resource  advance_help[] =
{
    {IM_EPG_COLORBUTTON_RED,       RS_HELP_COPY},
//    {IM_EPG_COLORBUTTON_GREEN,     RS_MP_HELP_MAKE_FOLDER},
    //{IM_MEDIAPLAY_HELPBUTTON_I,    0},
};
#define ADVANCE_HELP_CNT	(sizeof(advance_help)/sizeof(struct mp_help_item1_resource))

struct mp_help_item1_resource* helps1[] =
{
	music_help1,
	photo_help1,
	video_help1,
	record_help1,
};
UINT8 help_cnt1[] =
{
	MUSIC_HELP1_CNT,
	PHOTO_HELP1_CNT,
	VIDEO_HELP1_CNT,
	RECORD_HELP1_CNT,
};

#ifdef DLNA_DMP_SUPPORT
struct mp_help_item1_resource* dlna_helps1[] =
{
    dlna_help1,
};
UINT8 dlna_help_cnt1[] =
{
	DLNA_HELP1_CNT,
};
#endif

struct mp_help_item1_resource* helps2[] =
{
	music_help2,
	photo_help2,
	video_help2,
	record_help2,
};
UINT8 help_cnt2[] =
{
	MUSIC_HELP2_CNT,
	PHOTO_HELP2_CNT,
	VIDEO_HELP2_CNT,
	RECORD_HELP2_CNT,
};

struct mp_help_item1_resource* edithelps[] =
{
	edit_help,
	edit_help,
	edit_help,
	advance_help,
};
UINT8 edithelp_cnt[] =
{
	EDIT_HELP_CNT,
	EDIT_HELP_CNT,
	EDIT_HELP_CNT,
	ADVANCE_HELP_CNT,
};

void win_set_mp_pvr_title(UINT8 main_title, TITLE_TYPE title_type)
{
	BITMAP *pBmp;
	TEXT_FIELD *pTxt;
	struct mp_title_tab_resource* titleitem;
	TITLE_TYPE type;
	POBJECT_HEAD pObj;

#ifdef DLNA_DMP_SUPPORT
    if (mp_is_dlna_play())
    {
		titleitem = &dlna_title_tab[0];
		pBmp = &usb_title_bmp1;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt1;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);

		pBmp = &usb_title_bmp2;
		OSD_SetBitmapContent(pBmp, 0);
		pTxt = &usb_title_txt2;
		OSD_SetTextFieldContent(pTxt,STRING_ID,0);

		pBmp = &usb_title_bmp3;
		OSD_SetBitmapContent(pBmp, 0);
		pTxt = &usb_title_txt3;
		OSD_SetTextFieldContent(pTxt,STRING_ID,0);

		pBmp = &usb_title_bmp4;
		OSD_SetBitmapContent(pBmp, 0);
		pTxt = &usb_title_txt4;
		OSD_SetTextFieldContent(pTxt,STRING_ID,0);


    }
    else
#endif
    {
    	if(main_title == 1)
	{
		type = title_type;
		titleitem = &title_tab[type];
		pBmp = &usb_title_bmp1;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt1;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);

		type = (title_type+1)%TITLE_NUMBER;
		titleitem = &title_tab[type+TITLE_NUMBER];
		pBmp = &usb_title_bmp2;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt2;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);
     	OSD_SetColor(pTxt, TITLE_TXT2_SH, TITLE_TXT2_SH, TITLE_TXT2_SH, TITLE_TXT2_SH);

		type = (title_type+2)%TITLE_NUMBER;
		titleitem = &title_tab[type+TITLE_NUMBER];
		pBmp = &usb_title_bmp3;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt3;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);
     	OSD_SetColor(pTxt, TITLE_TXT2_SH, TITLE_TXT2_SH, TITLE_TXT2_SH, TITLE_TXT2_SH);

		type = (title_type+3)%TITLE_NUMBER;
		titleitem = &title_tab[type+TITLE_NUMBER];
		pBmp = &usb_title_bmp4;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt4;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);
     	OSD_SetColor(pTxt, TITLE_TXT2_SH, TITLE_TXT2_SH, TITLE_TXT2_SH, TITLE_TXT2_SH);
	}
	else
	{
		type = title_type;
		titleitem = &title_tab[type];
		pBmp = &usb_title_bmp1;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt1;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);

		type = (title_type+1)%TITLE_NUMBER;
		titleitem = &title_tab[type+TITLE_NUMBER*2];
		pBmp = &usb_title_bmp2;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt2;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);
     	OSD_SetColor(pTxt, TITLE_TXT2_GRY, TITLE_TXT2_GRY, TITLE_TXT2_GRY, TITLE_TXT2_GRY);

		type = (title_type+2)%TITLE_NUMBER;
		titleitem = &title_tab[type+TITLE_NUMBER*2];
		pBmp = &usb_title_bmp3;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt3;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);
     	OSD_SetColor(pTxt, TITLE_TXT2_GRY, TITLE_TXT2_GRY, TITLE_TXT2_GRY, TITLE_TXT2_GRY);

		type = (title_type+3)%TITLE_NUMBER;
		titleitem = &title_tab[type+TITLE_NUMBER*2];
		pBmp = &usb_title_bmp4;
		OSD_SetBitmapContent(pBmp, titleitem->bmp_id);
		pTxt = &usb_title_txt4;
		OSD_SetTextFieldContent(pTxt,STRING_ID,titleitem->str_id);
         	OSD_SetColor(pTxt, TITLE_TXT2_GRY, TITLE_TXT2_GRY, TITLE_TXT2_GRY, TITLE_TXT2_GRY);
    	}
    }
}

void win_draw_mp_pvr_title(void)
{
	POBJECT_HEAD pObj;

	pObj = (POBJECT_HEAD)&usb_title_con;
	OSD_DrawObject((POBJECT_HEAD)pObj,C_UPDATE_ALL);
}

//for example
//win_set_mpflielist_help1(edithelps[TITLE_RECORD],edithelp_cnt[TITLE_RECORD]);
//win_set_mpflielist_help2(NULL,0);

static void win_set_mpflielist_help1(struct mp_help_item1_resource *helpinfo,UINT8 item_count)
{
	UINT8 i = 0;
	BITMAP* pBmp;
	TEXT_FIELD* pTxt;
	struct mp_help_item1_resource* helpitem;

	for(i = 0; i < item_count;i++)
	{
		helpitem = &helpinfo[i];

		pBmp = pHelp1Btn_icons[i];
		OSD_SetBitmapContent(pBmp, helpitem->bmp_id);

		pTxt = pHelp1Txt_ids[i];
		OSD_SetTextFieldContent(pTxt,STRING_ID,helpitem->str_id);
	}

	if(item_count<HELPCNT)//some help item not show
	{
		for(i=item_count; i<HELPCNT; i++)
		{
			pBmp = pHelp1Btn_icons[i];
			OSD_SetBitmapContent(pBmp, 0);

			pTxt = pHelp1Txt_ids[i];
			OSD_SetTextFieldContent(pTxt,STRING_ID,0);
		}
	}

}

static void win_set_mpflielist_help2(struct mp_help_item1_resource *helpinfo,UINT8 item_count)
{
	UINT8 i = 0;
	BITMAP *pBtn;
	TEXT_FIELD *pTxt;
	struct mp_help_item1_resource* helpitem;

	for(i = 0; i < item_count;i++)
	{
		helpitem = &helpinfo[i];

		pBtn = pHelp2Btn_icons[i];
		OSD_SetBitmapContent(pBtn, helpitem->bmp_id);

		pTxt = pHelp2Txt_ids[i];
		OSD_SetTextFieldContent(pTxt,STRING_ID,helpitem->str_id);
	}

	if(item_count<HELPCNT)//some help item not show
	{
		for(i=item_count; i<HELPCNT; i++)
		{
			pBtn = pHelp2Btn_icons[i];
			OSD_SetBitmapContent(pBtn , 0);

			pTxt = pHelp2Txt_ids[i];
			OSD_SetTextFieldContent(pTxt,STRING_ID,0);
		}
	}
}

void win_set_mp_pvr_help_attr(UINT8 main_help, TITLE_TYPE title_type)
{
	POBJECT_HEAD pObj;
	UINT8 i = 0;
	TEXT_FIELD* pTxt;
	struct mp_help_item1_resource* helpitem;

	if(title_type == TITLE_RECORD)
	{
		pObj = (OBJECT_HEAD *)&g_win_record;
	}
	else
	{
		pObj = (OBJECT_HEAD *)&g_win_usb_filelist;
	}
	if(main_help == 1)
	{
		if(OSD_GetFocusID(pObj) == MP_DEVICE_ID)
		{
			switch(title_type)//ChengYu@20131001, change file list help icon
			{
			case TITLE_MUSIC:
				OSD_SetAttr(pHelp1Txt_ids[0], C_ATTR_ACTIVE);//switch
				OSD_SetAttr(pHelp1Txt_ids[1], C_ATTR_INACTIVE);//play list
				OSD_SetAttr(pHelp1Txt_ids[2], C_ATTR_INACTIVE);//fav
				OSD_SetAttr(pHelp1Txt_ids[3], C_ATTR_INACTIVE);//fav all
				OSD_SetAttr(pHelp1Txt_ids[4], C_ATTR_ACTIVE);

				OSD_SetAttr(pHelp2Txt_ids[0], C_ATTR_ACTIVE);//exit
				OSD_SetAttr(pHelp2Txt_ids[1], C_ATTR_INACTIVE);//edit
				OSD_SetAttr(pHelp2Txt_ids[2], C_ATTR_INACTIVE);//sort
				OSD_SetAttr(pHelp2Txt_ids[3], C_ATTR_INACTIVE);//repeat
				OSD_SetAttr(pHelp2Txt_ids[4], C_ATTR_ACTIVE);
				break;
			case TITLE_IMAGE:
				OSD_SetAttr(pHelp1Txt_ids[0], C_ATTR_ACTIVE);//switch
				OSD_SetAttr(pHelp1Txt_ids[1], C_ATTR_INACTIVE);//play list
				OSD_SetAttr(pHelp1Txt_ids[2], C_ATTR_INACTIVE);//fav
				OSD_SetAttr(pHelp1Txt_ids[3], C_ATTR_INACTIVE);//fav all
				OSD_SetAttr(pHelp1Txt_ids[4], C_ATTR_ACTIVE);

				OSD_SetAttr(pHelp2Txt_ids[0], C_ATTR_ACTIVE);//exit
				OSD_SetAttr(pHelp2Txt_ids[1], C_ATTR_INACTIVE);//edit
				OSD_SetAttr(pHelp2Txt_ids[2], C_ATTR_INACTIVE);//sort
				OSD_SetAttr(pHelp2Txt_ids[3], C_ATTR_INACTIVE);//setup
				OSD_SetAttr(pHelp2Txt_ids[4], C_ATTR_INACTIVE);//multi view
				break;
			case TITLE_VIDEO:
				OSD_SetAttr(pHelp1Txt_ids[0], C_ATTR_ACTIVE);//switch
				OSD_SetAttr(pHelp1Txt_ids[1], C_ATTR_INACTIVE);//edit
				OSD_SetAttr(pHelp1Txt_ids[2], C_ATTR_INACTIVE);//sort
				OSD_SetAttr(pHelp1Txt_ids[3], C_ATTR_INACTIVE);//repeat
				OSD_SetAttr(pHelp1Txt_ids[4], C_ATTR_ACTIVE);

				OSD_SetAttr(pHelp2Txt_ids[0], C_ATTR_ACTIVE);//exit
				OSD_SetAttr(pHelp2Txt_ids[1], C_ATTR_ACTIVE);
				OSD_SetAttr(pHelp2Txt_ids[2], C_ATTR_ACTIVE);
				OSD_SetAttr(pHelp2Txt_ids[3], C_ATTR_ACTIVE);
				OSD_SetAttr(pHelp2Txt_ids[4], C_ATTR_ACTIVE);
				break;
			case TITLE_RECORD:
				OSD_SetAttr(pHelp1Txt_ids[0], C_ATTR_ACTIVE);//switch
				OSD_SetAttr(pHelp1Txt_ids[1], C_ATTR_INACTIVE);//rename
				OSD_SetAttr(pHelp1Txt_ids[2], C_ATTR_INACTIVE);//lock
				OSD_SetAttr(pHelp1Txt_ids[3], C_ATTR_INACTIVE);//delete
				OSD_SetAttr(pHelp1Txt_ids[4], C_ATTR_ACTIVE);//

				OSD_SetAttr(pHelp2Txt_ids[0], C_ATTR_ACTIVE);//exit
				OSD_SetAttr(pHelp2Txt_ids[1], C_ATTR_ACTIVE);
				OSD_SetAttr(pHelp2Txt_ids[2], C_ATTR_ACTIVE);
				OSD_SetAttr(pHelp2Txt_ids[3], C_ATTR_ACTIVE);
				OSD_SetAttr(pHelp2Txt_ids[4], C_ATTR_ACTIVE);
				break;
			default:
				break;
			}
		}
		else
		{
			for(i = 0; i < help_cnt1[title_type];i++)
			{
				pTxt = pHelp1Txt_ids[i];
				OSD_SetAttr(pTxt, C_ATTR_ACTIVE);
			}

			for(i = 0; i < help_cnt2[title_type];i++)
			{
				pTxt = pHelp2Txt_ids[i];
				OSD_SetAttr(pTxt, C_ATTR_ACTIVE);
			}
		}
	}
	else //edit&advance help
	{
		if(OSD_GetFocusID(pObj) == MP_DEVICE_ID)
		{
			switch(title_type)
			{
			case TITLE_MUSIC:
			case TITLE_IMAGE:
			case TITLE_VIDEO:
				OSD_SetAttr(pHelp1Txt_ids[0], C_ATTR_INACTIVE);//rename
				OSD_SetAttr(pHelp1Txt_ids[1], C_ATTR_INACTIVE);//copy
				OSD_SetAttr(pHelp1Txt_ids[2], C_ATTR_INACTIVE);//delete
				OSD_SetAttr(pHelp1Txt_ids[3], C_ATTR_INACTIVE);//+folder
				OSD_SetAttr(pHelp1Txt_ids[4], C_ATTR_ACTIVE);//info
				break;
			case TITLE_RECORD:
				OSD_SetAttr(pHelp1Txt_ids[0], C_ATTR_INACTIVE);//copy
				OSD_SetAttr(pHelp1Txt_ids[1], C_ATTR_ACTIVE);//info
				OSD_SetAttr(pHelp1Txt_ids[2], C_ATTR_ACTIVE);//
				OSD_SetAttr(pHelp1Txt_ids[3], C_ATTR_ACTIVE);//
				OSD_SetAttr(pHelp1Txt_ids[4], C_ATTR_ACTIVE);//
				break;
			default:
				break;
			}

		}
		else
		{
			for(i = 0; i < edithelp_cnt[title_type];i++)
			{
				pTxt = pHelp1Txt_ids[i];
				OSD_SetAttr(pTxt, C_ATTR_ACTIVE);
			}
		}
	}
}

void win_set_mp_pvr_help(UINT8 main_help, TITLE_TYPE title_type)
{
#ifdef DLNA_DMP_SUPPORT
    if (mp_is_dlna_play())
    {
		win_set_mpflielist_help1(dlna_helps1[0],dlna_help_cnt1[0]);
		win_set_mpflielist_help2(NULL,0);
    }
    else
#endif
    {
	if(main_help == 1)
	{
		win_set_mpflielist_help1(helps1[title_type],help_cnt1[title_type]);
		win_set_mpflielist_help2(helps2[title_type],help_cnt2[title_type]);
	}
	else
	{
		win_set_mpflielist_help1(edithelps[title_type],edithelp_cnt[title_type]);
		win_set_mpflielist_help2(NULL,0);
	}
	win_set_mp_pvr_help_attr(main_help, title_type);
    }

}

void win_draw_mp_pvr_help(void)
{
	POBJECT_HEAD pObj;

	pObj = (POBJECT_HEAD)&usb_help_win;
	OSD_DrawObject((POBJECT_HEAD)pObj,C_UPDATE_ALL);
}

///////////////////////////////////////
// end of title & help UI definition
///////////////////////////////////////


void win_get_fullname(char *fullname,char *path, char *name)
{
	STRCPY(fullname, path);
	strcat(fullname, "/");
	strcat(fullname, name);
}

void win_get_parent_dirname(char *parentpath,char *path)
{//get parent dir's path, as: /a/b/->/a/
	UINT16	i;

	STRCPY(parentpath, path);
	i = STRLEN(parentpath);
	while ((parentpath[i] != '/') && (i > 0))
	{
		i--;
	}
	if (i != 0)
	{
		parentpath[i] = '\0';
	}
	else
	{
		i += 1;
		parentpath[i] = '\0';
	}
}

#define FILE_EXT_NAME_SIZE 5
#define FILE_NAME_DISPLAY_MAXLEN 22 //for usb upgrade file name too long to system-down

void filter_unkownfont_name(const char *src_filename, char *display_filename)
{
	int i, j;

	for (i = 0, j = 0; src_filename[i] != '\0'; i++)
	{
		if ((src_filename[i] & 0x80) == 0x80)
		{
			if ((src_filename[i] & 0xc0) == 0xc0)
			{
				display_filename[j] = '-';
				j++;
			}
		}
		else
		{
			display_filename[j] = src_filename[i];
			j++;
		}
	}
	display_filename[j] = '\0';

	if (j > FILE_NAME_DISPLAY_MAXLEN)
	{
		for (i = j - 1; (display_filename[i] != '.') && (i >= 0); i--);
		if ((i < 0) || ((j - 1 - i) > FILE_NAME_DISPLAY_MAXLEN -FILE_EXT_NAME_SIZE))
		{
			//display_filename[FILE_NAME_DISPLAY_MAXLEN] = '\0';
			display_filename[FILE_NAME_DISPLAY_MAXLEN - 3] = '\0';
			strcat(display_filename, "...");
		}
		else
		{
			display_filename[FILE_NAME_DISPLAY_MAXLEN - (j - i) - 3] = '\0';
			strcat(display_filename, "...");
			strcat(display_filename, display_filename + i);
		}
	}

	return;
}

void win_shorten_filename(const char *src_filename, char *display_filename)
{
	int i, j;

	STRCPY(display_filename, src_filename);
	for (j = 0; display_filename[j] != '\0'; j++);

	if (j > FILE_NAME_DISPLAY_MAXLEN)
	{
		for (i = j - 1; (display_filename[i] != '.') && (i >= 0); i--);
		if ((i < 0) || ((j - 1 - i) > FILE_NAME_DISPLAY_MAXLEN -FILE_EXT_NAME_SIZE))
		{
			//display_filename[FILE_NAME_DISPLAY_MAXLEN] = '\0';
			display_filename[FILE_NAME_DISPLAY_MAXLEN - 3] = '\0';
			if((display_filename[FILE_NAME_DISPLAY_MAXLEN - 4] & 0xc0) == 0xc0)
			{
				display_filename[FILE_NAME_DISPLAY_MAXLEN - 4] = '\0';
			}
			strcat(display_filename, "...");
		}
		else
		{
			display_filename[FILE_NAME_DISPLAY_MAXLEN - (j - i) - 3] = '\0';
			if((display_filename[FILE_NAME_DISPLAY_MAXLEN - (j - i) - 4] & 0xc0) == 0xc0)
			{
				display_filename[FILE_NAME_DISPLAY_MAXLEN - (j - i) - 4] = '\0';
			}
			strcat(display_filename, "...");
			strcat(display_filename, display_filename + i);
		}
	}

	return;
}


void win_fill_filename(const char *src_filename, char *display_filename)
{
	int i, j;
	BOOL find_end_flg = FALSE;
	STRCPY(display_filename, src_filename);

	j = 0;
	while(j < FILE_NAME_DISPLAY_MAXLEN )
	{
		if(display_filename[j] == '\0')
		{
			find_end_flg = TRUE;
		}

		if(find_end_flg)
			{
			display_filename[j] = ' '; //Fill with Space
			}
		j++;
	}
	if(j > 0)
	{
		display_filename[j-1] = '\0';
	}
	else
		{
		display_filename[j] = '\0';
	}
	return;
}

RET_CODE win_get_display_dirname(char *display_dirname, char *src_dirname)
{
	char dirname1[FULL_PATH_SIZE];
	char dirname2[MAX_FILE_NAME_SIZE];
	char display_dirname2[MAX_FILE_NAME_SIZE];
	UINT16 i;

	if(!STRCMP(src_dirname, FS_ROOT_DIR))
	{
		STRCPY(display_dirname, "Root");
	}
	else
	{
		STRCPY(dirname1, "Root");
		strcat(dirname1, src_dirname+4);

		i = STRLEN(dirname1);
		while ((dirname1[i] != '/') && (i > 0))
		{
			i--;
		}
		if (i != 0)
		{
			STRCPY(dirname2, dirname1+i);
			//filter_unkownfont_name(dirname2,display_dirname2);//filter name that can not be show
			win_shorten_filename(dirname2,display_dirname2);
			dirname1[i] = '\0';
			//filter_unkownfont_name(dirname1,display_dirname);//filter name that can not be show
			win_shorten_filename(dirname1,display_dirname);
			strcat(display_dirname, display_dirname2);
		}
		else
		{
			//filter_unkownfont_name(dirname1,display_dirname);//filter name that can not be show
			win_shorten_filename(dirname1,display_dirname);
		}
	}
	return RET_SUCCESS;
}

UINT32 win_get_file_idx(FileListHandle file_list, char *file_name)
{
	UINT32 uIdx,uTotal;
	FileInfo file_node;
	char full_name[MAX_FILE_NAME_SIZE] = {0};
	unsigned int dir_num,file_num;

	get_file_list_info(file_list, &dir_num, &file_num, NULL);
	uTotal = dir_num+file_num;
	for(uIdx=0; uIdx<uTotal; uIdx++)
	{
		get_file_from_file_list(file_list, uIdx+1, &file_node);
		win_get_fullname(full_name, file_node.path, file_node.name);
		if(STRCMP(file_name, full_name) == 0)
			break;
	}
	if(uIdx == uTotal)
		uIdx = (UINT16)(~0);

	return uIdx;
}

BOOL win_check_openroot(FileListHandle file_list)
{
	char file_path[MAX_FILE_NAME_SIZE + 1];

	get_file_list_info(file_list, NULL, NULL, file_path);
	if(!STRCMP(file_path, FS_ROOT_DIR))
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}


RET_CODE win_image_file_play(char *file, unsigned char rotate)
{
	int ret_val;
	struct image_slideshow_effect effect;

#ifdef DLNA_DMP_SUPPORT
    if (mp_is_dlna_play())
    {
        win_dlna_play_preset(file, 2);
    }
#endif

	effect.mode = osal_get_tick() % 5 + 1;
	switch(effect.mode)
	{
		case M_SHUTTERS:
			effect.mode_param.shuttles_param.direction = osal_get_tick() % 2;
			effect.mode_param.shuttles_param.time = 100;
			break;
		case M_BRUSH:
			effect.mode_param.brush_param.direction  = osal_get_tick() % 2;
			effect.mode_param.brush_param.time = 3;
			break;
		case M_SLIDE:
			effect.mode_param.slide_param.direction =  osal_get_tick() % 2;
			effect.mode_param.slide_param.time = 10;
			break;
		case M_RANDOM:
			effect.mode_param.random_param.type = osal_get_tick() % 3;
			effect.mode_param.random_param.time = 1;
			break;
		case M_FADE:
			effect.mode_param.fade_param.type = 0;
			effect.mode_param.fade_param.time = 0;
			break;
		default:
			break;
	}
	ret_val = image_decode_ex(file, IMAGEDEC_FULL_SRN, 0, 0, 720, 576, rotate, &effect);

	if(ret_val < 0)
	{
		return RET_FAILURE;
	}

	return RET_SUCCESS;
}

RET_CODE win_image_file_preview(char *file, RECT rect_info, int mode)
{
	int ret_val;

	ret_val = image_decode(file, mode, rect_info.left, rect_info.top, rect_info.right - rect_info.left, rect_info.bottom - rect_info.top, ANG_ORI);

	if(ret_val < 0)
	{
		return RET_FAILURE;
	}
	return RET_SUCCESS;
}

RET_CODE win_get_next_device(char *current_device, char *next_device, UINT8 fLeft)
{
	RET_CODE ret = RET_SUCCESS;
	char device_arry[MAX_DEVICE_NUM][3];
	UINT8 device_arry_size = MAX_DEVICE_NUM*3;
	UINT8 device_num;
	UINT8 i, next_device_idx;

	if(RET_FAILURE == get_current_stroage_device1(STORAGE_TYPE_ALL, device_arry, &device_arry_size))
	{
		return RET_FAILURE;
	}

	device_num = device_arry_size/3;
	for(i=0; i<device_num; i++)
	{
		if(strncmp(device_arry[i], current_device, 3) == 0)
			break;
	}

	if(fLeft == TRUE)
	{
		next_device_idx = (i+device_num-1)%device_num;
	}
	else
	{
		next_device_idx = (i+1)%device_num;
	}

	MEMCPY(next_device, device_arry[next_device_idx], 3);
	next_device[3] = '\0';

	return RET_SUCCESS;
}

void win_get_display_devicename(char *display_devicename, char *lib_devicename)
{
	char temp[2];

	if(strncmp(lib_devicename, "ud", 2) == 0)
	{
		STRCPY(display_devicename, "USB");
	}
	else if(strncmp(lib_devicename, "hd", 2) == 0)
	{
		STRCPY(display_devicename, "HDD");
	}
	else if(strncmp(lib_devicename, "sd", 2) == 0)
	{
		STRCPY(display_devicename, "SD");
	}
	else if(strncmp(lib_devicename, "dlna", 2) == 0)
	{
		STRCPY(display_devicename, "DLNA");
		return;
	}
	else
	{
		STRCPY(display_devicename, "");
	}

	temp[0] = lib_devicename[2] - 'a' + '1';
	temp[1] = '\0';
	strcat(display_devicename, temp);
}

void win_set_device_icon(BITMAP *pBmp, char *lib_devicename)
{
	if(strncmp(lib_devicename, "ud", 2) == 0)
	{
		OSD_SetBitmapContent(pBmp, IM_MP3_ICON_MEM_USB);
	}
	else if(strncmp(lib_devicename, "hd", 2) == 0)
	{
		OSD_SetBitmapContent(pBmp, IM_MP3_ICON_MEM_HARDD);
	}
	else if(strncmp(lib_devicename, "sd", 2) == 0)
	{
		OSD_SetBitmapContent(pBmp, IM_MP3_ICON_MEM_SD);
	}
	else
	{
		OSD_SetBitmapContent(pBmp, 0);
	}
}

FileListType win_type_title2filelist(TITLE_TYPE title_type)
{
	FileListType list_type;

	switch(title_type)
	{
	case TITLE_MUSIC:
		list_type = MUSIC_FILE_LIST;
		break;
	case TITLE_IMAGE:
		list_type = IMAGE_FILE_LIST;
		break;
	case TITLE_VIDEO:
		list_type = VIDEO_FILE_LIST;
		break;
	default:
		list_type = MUSIC_FILE_LIST;
		break;
	}

#ifdef DLNA_DMP_SUPPORT
    if (mp_is_dlna_play())
        list_type = DLNA_FILE_LIST;
#endif

	return list_type;
}

#ifndef __MM_FB5_Y_START_ADDR
#define __MM_FB5_Y_LEN          __MM_FB3_Y_LEN
#define __MM_FB5_C_LEN          __MM_FB3_C_LEN
#define __MM_FB6_Y_LEN          __MM_FB3_Y_LEN
#define __MM_FB6_C_LEN          __MM_FB3_C_LEN

#define __MM_FB5_Y_START_ADDR	((__MM_FB4_C_START_ADDR+__MM_FB4_C_LEN)&0XFFFFFE00)
#define __MM_FB5_C_START_ADDR   ((__MM_FB5_Y_START_ADDR+__MM_FB5_Y_LEN)&0XFFFFFE00)
#define __MM_FB6_Y_START_ADDR	((__MM_FB5_C_START_ADDR+__MM_FB5_C_LEN)&0XFFFFFE00)
#define __MM_FB6_C_START_ADDR   ((__MM_FB6_Y_START_ADDR+__MM_FB6_Y_LEN)&0XFFFFFE00)
#endif

static void config_deo_frm_buf(void)
{
	struct vpo_device *gpvpo_sd;
	Imagedec_frm deo_frm_buf[4];
	gpvpo_sd = gpvpo_sd = (struct vpo_device *)dev_get_by_id(HLD_DEV_TYPE_DIS, 1);
	if(NULL != gpvpo_sd)
	{
		deo_frm_buf[0].frm_y_addr = (UINT8 *)__MM_FB3_Y_START_ADDR;
		deo_frm_buf[0].frm_y_len = __MM_FB3_Y_LEN;
		deo_frm_buf[0].frm_c_addr = (UINT8 *)__MM_FB3_C_START_ADDR;
		deo_frm_buf[0].frm_c_len = __MM_FB3_C_LEN;
		deo_frm_buf[0].busy = 0;
		deo_frm_buf[1].frm_y_addr = (UINT8 *)__MM_FB4_Y_START_ADDR;
		deo_frm_buf[1].frm_y_len = __MM_FB4_Y_LEN;
		deo_frm_buf[1].frm_c_addr = (UINT8 *)__MM_FB4_C_START_ADDR;
		deo_frm_buf[1].frm_c_len = __MM_FB4_C_LEN;
		deo_frm_buf[1].busy = 0;
        deo_frm_buf[2].frm_y_addr = (UINT8 *)__MM_FB5_Y_START_ADDR;
        deo_frm_buf[2].frm_y_len = __MM_FB5_Y_LEN;
        deo_frm_buf[2].frm_c_addr = (UINT8 *)__MM_FB5_C_START_ADDR;
        deo_frm_buf[2].frm_c_len = __MM_FB5_C_LEN;
        deo_frm_buf[2].busy = 0;
        deo_frm_buf[3].frm_y_addr = (UINT8 *)__MM_FB6_Y_START_ADDR;
        deo_frm_buf[3].frm_y_len = __MM_FB6_Y_LEN;
        deo_frm_buf[3].frm_c_addr = (UINT8 *)__MM_FB6_C_START_ADDR;
        deo_frm_buf[3].frm_c_len = __MM_FB6_C_LEN;
        deo_frm_buf[3].busy = 0;
		imagedec_ioctl(1, IMAGEDEC_IO_CMD_CFG_DEO_FRM, (UINT32)(&deo_frm_buf));
	}
}

#ifdef _INVW_JUICE //v0.1.4
// Set the alternative media player callback handler
void win_media_network_player_set_alternative_callback(mp_callback_func mp_cb)
{
	if(mp_cb)
	{
		mp_alternative_cb = mp_cb;
	}
}


// Clear the alternative media player callback handler
void win_media_network_player_clear_alternative_callback(void)
{
	mp_alternative_cb = 0;
}


// Retrieve the alternative media player callback handler
mp_callback_func win_media_network_player_get_alternative_callback(void)
{
	return mp_alternative_cb;
}
#endif



#if defined(_INVW_JUICE ) || defined(PLAY_TEST)
RET_CODE win_media_network_player_init(mp_callback_func mp_cb)
{
	RET_CODE ret = RET_SUCCESS;
	PeConfig pe_cfg;
    struct pe_video_cfg_extra video_cfg_extra;

	MEMSET(&pe_cfg, 0, sizeof(pe_cfg));
    MEMSET(&video_cfg_extra, 0, sizeof(struct pe_video_cfg_extra));

	//fill the music engine config
	#if 0//chunpin _INVW_JUICE
	pe_cfg.music.pcm_out_buff = __MM_TTX_BS_START_ADDR & 0x8fffffff;
	#else
//	pe_cfg.music.pcm_out_buff = (__MM_TTX_BS_START_ADDR & 0x8fffffff);
	pe_cfg.music.pcm_out_buff = (__MM_TTX_BS_START_ADDR & 0x8fffffff)+1;
	#endif
	pe_cfg.music.pcm_out_buff_size = __MM_TTX_BS_LEN & 0x8fffffff;
	pe_cfg.music.processed_pcm_buff = __MM_SUB_BS_START_ADDR & 0x8fffffff;
	pe_cfg.music.processed_pcm_buff_size = __MM_SUB_BS_LEN & 0x8fffffff;
	pe_cfg.music.mp_cb = mp_cb;

#ifdef _INVW_JUICE
	pe_cfg.music.pe_cache_buf_start_addr= 0;
	pe_cfg.music.pe_cache_buf_len= 0;
#endif

	//fill the image engine config
	pe_cfg.image.frm_y_size	= __MM_FB0_Y_LEN;
	pe_cfg.image.frm_y_addr	= __MM_FB0_Y_START_ADDR;
	pe_cfg.image.frm_c_size	= __MM_FB0_C_LEN;
	pe_cfg.image.frm_c_addr	= __MM_FB0_C_START_ADDR;
	pe_cfg.image.frm2_y_size = __MM_FB1_Y_LEN;
	pe_cfg.image.frm2_y_addr = __MM_FB1_Y_START_ADDR;
	pe_cfg.image.frm2_c_size = __MM_FB1_C_LEN;
	pe_cfg.image.frm2_c_addr = __MM_FB1_C_START_ADDR;
	pe_cfg.image.frm3_y_size = __MM_FB2_Y_LEN;
	pe_cfg.image.frm3_y_addr = __MM_FB2_Y_START_ADDR;
	pe_cfg.image.frm3_c_size = __MM_FB2_C_LEN;
	pe_cfg.image.frm3_c_addr = __MM_FB2_C_START_ADDR;
	pe_cfg.image.decoder_buf = (UINT8 *)__MM_MP_BUFFER_ADDR;
	pe_cfg.image.decoder_buf_len = __MM_MP_BUFFER_LEN;
	pe_cfg.image.mp_cb = mp_cb;

	//fill the video engine config
	pe_cfg.video.mp_cb = mp_cb;
	pe_cfg.video.decoder_buf = __MM_VIDEO_FILE_BUF_ADDR;
	pe_cfg.video.decoder_buf_len = __MM_VIDEO_FILE_BUF_LEN;
	pe_cfg.video.mm_vbv_len = __MM_VBV_LEN;
	pe_cfg.video.reserved = 0;
#if 1//chunpin _INVW_JUICE
    	pe_cfg.video.disable_seek = TRUE;//disable network mediaplay seek function
#endif
    pe_cfg.video.new_retry_mechanism = TRUE;

#ifdef M36F_CHIP_MODE
#if (SYS_SDRAM_SIZE == 128 || SYS_SDRAM_SIZE == 64)
    // video file buffer is seperated with frame buffer
    #if (__MM_FB_TOP_ADDR > __MM_VIDEO_FILE_BUF_ADDR)
    pe_cfg.video.decoder_buf_len = __MM_FB_TOP_ADDR - __MM_VIDEO_FILE_BUF_ADDR;
    #endif
    video_cfg_extra.frame_buf_base = __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.frame_buf_len = __MM_FB_TOP_ADDR - __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.reserved[0] = (UINT32)font_array_1bit_subt;
    video_cfg_extra.reserved[1] = 7; //sizeof(font_array_1bit_subt) / sizeof(font_array_1bit_subt[0]);
    #ifdef SUPPORT_CAS9
    video_cfg_extra.frame_buf_base = (__MM_EPG_BUFFER_START+0xfff)&0xfffff000;
    video_cfg_extra.frame_buf_len = __MM_FB_TOP_ADDR - video_cfg_extra.frame_buf_base;
    video_cfg_extra.reserved[2] = video_cfg_extra.frame_buf_base;
    video_cfg_extra.reserved[3] = video_cfg_extra.frame_buf_len;
    #ifdef SD_PVR
	video_cfg_extra.reserved[4] = (720<<16)|(576);  //OSD:720*576
    #endif
    #endif
    pe_cfg.video.reserved = (UINT32)(&video_cfg_extra);
#endif
#else
    // M3602
    // video file buffer is seperated with frame buffer
    video_cfg_extra.frame_buf_base = __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.frame_buf_len = __MM_FB_TOP_ADDR - __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.reserved[0] = font_array_1bit_subt;
    video_cfg_extra.reserved[1] = 7; //sizeof(font_array_1bit_subt) / sizeof(font_array_1bit_subt[0]);
    pe_cfg.video.reserved = (UINT32)(&video_cfg_extra);
#endif

	ret = media_player_init(&pe_cfg);
	config_deo_frm_buf();
	return ret;
}

#endif
RET_CODE win_media_player_init(mp_callback_func mp_cb)
{
	RET_CODE ret = RET_SUCCESS;
	PeConfig pe_cfg;
    struct pe_video_cfg_extra video_cfg_extra;

	MEMSET(&pe_cfg, 0, sizeof(pe_cfg));
    MEMSET(&video_cfg_extra, 0, sizeof(struct pe_video_cfg_extra));

	//fill the music engine config
	pe_cfg.music.pcm_out_buff = __MM_TTX_BS_START_ADDR & 0x8fffffff;
	pe_cfg.music.pcm_out_buff_size = __MM_TTX_BS_LEN & 0x8fffffff;
	pe_cfg.music.processed_pcm_buff = __MM_SUB_BS_START_ADDR & 0x8fffffff;
	pe_cfg.music.processed_pcm_buff_size = __MM_SUB_BS_LEN & 0x8fffffff;
	pe_cfg.music.mp_cb = mp_cb;
	pe_cfg.music.pe_cache_buf_start_addr= 0;
	pe_cfg.music.pe_cache_buf_len= 0;

	//fill the image engine config
	pe_cfg.image.frm_y_size	= __MM_FB0_Y_LEN;
	pe_cfg.image.frm_y_addr	= __MM_FB0_Y_START_ADDR;
	pe_cfg.image.frm_c_size	= __MM_FB0_C_LEN;
	pe_cfg.image.frm_c_addr	= __MM_FB0_C_START_ADDR;
	pe_cfg.image.frm2_y_size = __MM_FB1_Y_LEN;
	pe_cfg.image.frm2_y_addr = __MM_FB1_Y_START_ADDR;
	pe_cfg.image.frm2_c_size = __MM_FB1_C_LEN;
	pe_cfg.image.frm2_c_addr = __MM_FB1_C_START_ADDR;
	pe_cfg.image.frm3_y_size = __MM_FB2_Y_LEN;
	pe_cfg.image.frm3_y_addr = __MM_FB2_Y_START_ADDR;
	pe_cfg.image.frm3_c_size = __MM_FB2_C_LEN;
	pe_cfg.image.frm3_c_addr = __MM_FB2_C_START_ADDR;
#ifdef DUAL_ENABLE
	pe_cfg.image.decoder_buf = (UINT8 *)__MM_MP_BUFFER_ADDR;
	pe_cfg.image.decoder_buf_len = __MM_MP_BUFFER_LEN;
#else
	pe_cfg.image.decoder_buf = (UINT8 *)__MM_TTX_BS_START_ADDR+__MM_TTX_BS_LEN;
	pe_cfg.image.decoder_buf_len = __MM_MP_BUFFER_ADDR+__MM_MP_BUFFER_LEN -__MM_TTX_BS_START_ADDR-__MM_TTX_BS_LEN;
#endif
	pe_cfg.image.mp_cb = mp_cb;

	//fill the video engine config
	pe_cfg.video.mp_cb = mp_cb;
	pe_cfg.video.decoder_buf = __MM_VIDEO_FILE_BUF_ADDR;
	pe_cfg.video.decoder_buf_len = __MM_VIDEO_FILE_BUF_LEN;
	pe_cfg.video.mm_vbv_len = __MM_VBV_LEN;
	pe_cfg.video.reserved = 0;
    	pe_cfg.video.disable_seek = TRUE;//disable network mediaplay seek function

#ifdef M36F_CHIP_MODE
#if (SYS_SDRAM_SIZE == 128 || SYS_SDRAM_SIZE == 64 || SYS_SDRAM_SIZE == 256)
    // video file buffer is seperated with frame buffer
    #if (__MM_FB_TOP_ADDR > __MM_VIDEO_FILE_BUF_ADDR)
    pe_cfg.video.decoder_buf_len = __MM_FB_TOP_ADDR - __MM_VIDEO_FILE_BUF_ADDR;
    #endif
    video_cfg_extra.frame_buf_base = __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.frame_buf_len = __MM_FB_TOP_ADDR - __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.reserved[0] = (UINT32)font_array_1bit_subt;
    video_cfg_extra.reserved[1] = 7; //sizeof(font_array_1bit_subt) / sizeof(font_array_1bit_subt[0]);
    #ifdef SUPPORT_CAS9
    video_cfg_extra.frame_buf_base = (__MM_EPG_BUFFER_START+0xfff)&0xfffff000;
    video_cfg_extra.frame_buf_len = __MM_FB_TOP_ADDR - video_cfg_extra.frame_buf_base;
    video_cfg_extra.reserved[2] = video_cfg_extra.frame_buf_base;
    video_cfg_extra.reserved[3] = video_cfg_extra.frame_buf_len;
    #endif
    //pe_cfg.video.reserved = (UINT32)(&video_cfg_extra);
#endif
#else
    // M3602
    // video file buffer is seperated with frame buffer
    video_cfg_extra.frame_buf_base = __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.frame_buf_len = __MM_FB_TOP_ADDR - __MM_FB_BOTTOM_ADDR;
    video_cfg_extra.reserved[0] = font_array_1bit_subt;
    video_cfg_extra.reserved[1] = 7; //sizeof(font_array_1bit_subt) / sizeof(font_array_1bit_subt[0]);
    //pe_cfg.video.reserved = (UINT32)(&video_cfg_extra);
#endif

#ifdef IMG_2D_TO_3D
    pe_cfg.image.ALi_pic_2dto3d = ALi_pic_2dto3d;
#ifndef DUAL_ENABLE   // 3811 64M memory location
#ifdef _SUPPORT_64M_MEM
    pe_cfg.image.decoder_buf = (UINT8 *)__MM_TTX_BS_START_ADDR+__MM_TTX_BS_LEN;
	pe_cfg.image.decoder_buf_len = __MM_FB_BOTTOM_ADDR + 0xE00000 -__MM_TTX_BS_START_ADDR-__MM_TTX_BS_LEN;
    //video_cfg_extra.frame_buf_base = __MM_FB2_C_START_ADDR + __MM_FB2_C_LEN;//__MM_FB_BOTTOM_ADDR;
    //video_cfg_extra.frame_buf_len = __MM_FB_TOP_ADDR - __MM_FB2_C_START_ADDR - __MM_FB2_C_LEN;//__MM_FB_BOTTOM_ADDR;
#endif
#endif
#endif


    pe_cfg.video.reserved = (UINT32)(&video_cfg_extra);
    pe_cfg.video.new_retry_mechanism = TRUE;
	ret = media_player_init(&pe_cfg);
	config_deo_frm_buf();
	return ret;
}


#ifdef ES_PLAYER_TEST
/**********************es player demo**************************************/
/* AWindH264.h264 every frame size */
static UINT32 frame_size[] =
{
    140898,	3221,	5601,	24314,	56859,	13455,	31754,	20593,	37285,	24512,
    45513,	22875,	26959,	24867,	25709,	25544,	41039,	26306,	28103,	27525,
    31509,	31950,	32494,	31606,	32534,	30997,	33557,	30466,	31926,	30601,
    32070,	31377,	34337,	33151,	72224,	32803,	31760,	32173,	29849,	29729,
    31286,	34497,	28756,	31877,	26168,	38159,	31117,	30298,	34097,	29890,
    32814,	31903,	31717,	30299,	30272,	31933,	33917,	40881,	57614,	50281,
    53449,	51582,	51822,	70068,	19019,	17418,	17878,	41741,	58781,	55272,
    53929,	51239,	55766,	46969,	48376,	49092,	47846,	56016,	48733,	43065,
    53618,	48955,	47887,	43727,	44588,	45241,	47634,	49321,	49213,	48939,
    55397,	48487,	47949,	48112,	43635,	41967,	17470,	13006,	30445,	43769,
    33192,	36328,	37141,	36789,	40140,	37656,	38214,	38765,	38422,	37963,
    38689,	40374,	39831,	35833,	33850,	34239,	33545,	33390,	37730,	36207,
    34742,	33485,	34030,	33115,	34534,	32871,	34562,	33289,	34045,	33279,
    32165,	46935,	31645,	37689,	33466,	36873,	37800,	37675,	35564,	34055,
    36163,	35650,	35029,	34398,	35439,	37189,	35526,	37572,	35883,	12852,
    51773,	42115,	41209,	40383,	10253,	21816,	82328,	59178,	74559,	76526,
    64621,	74136,	65358,	72711,	62381,	66354,	83045,	63550,	74507,	68286,
    70764,	76701,	47276,	52644,	48681,	47419,	45430,	46449,	44826,	40315,
    39680,	42816,	40722,	38388,	38395,	40235,	45069,	43949,	42892,	42067,
    74516,	35540,	40648,	34165,	37245,	35810,	41224,	36549,	43633,	36290,
    43129,	55940,	37423,	41867,	36490,	41791,	36300,	38107,	54002,	39779,
    32497,	35487,	31254,	35332,	30092,	32876,	28979,	32891,	29140,	42809,
    35625,	38537,	34145,	39045,	34715,	37759,	26430,	30976,	39227,	41263,
    36558,	30011,	28512,	42410,	36408,	40168,	33973,	39834,	36699,	39807,
    36940,	42007,	36035,	40694,	42851,	36026,	35333,	32375,	38582,	34569,
    106677,	18704,	23609,	27483,	27394,	29854,	33704,	29037,	36075,	32132,
    80940,	35433,	32625,	37239,	38036,	34660,	35237,	45922,	35670,	32172,
    46012,	32892,	38029,	36483,	36445,	34996,	38824,	39203,	40594,	38780,
    42705,	43292,	41418,	26154,	26042,	23153,	26578,	21605,	23912,	25694,
    28466,	25824,	32095,	17983,	17867,	22655,	19500,	22991,	22584,	31883,
    31296,	30275,	23878,	18512,	20611,	27405,	23377,	26159,	18300,	18155,
    17718,	22682,	22646,	23612,	22211,	25955,	24418,	61618,	20273,	26422,
    25340,	26468,	25169,	35241,	33468,	34811,	24798,	35357,	26098,	29837,
    30076,	30261,	31932,	33327,	33957,	19257,	13174,	9335,	27508,	47650,
    26811,	23252,	20611,	18409,	18403,	35694,	15947,	21221,	16614,	21872,
    19401,	18578,	20042,	18075,	17918,	18065,	18695,	18114,	18273,	18727,
    20564,	20560,	19307,	19622,	24157,	17887,	28926,	24461,	25411,	24485,
    23355,	20908,	20002,	27319,	21098,	22673,	23393,	22795,	22894,	23197,
    28430,	24903,	21493,	22491,	22136,	21060,	28322,	26128,	25914,	27021,
    26556,	24644,	24376,	24687,	23819,	23286,	22434,	21192,	21732,	21278,
    26403,	22890,	24324,	23363,	24991,	48108,	30689,	27967,	23789,	24398,
    22604,	22578,	22396,	23333,	23774,	29517,	23679,	23980,	24151,	24306,
    24644,	30258,	28626,	14782,	32393,	27229,	23170,	24025,	22047,	21900,
    24021,	24225,	25875,	23171,	24091,	21691,	23418,	22876,	25141,	24914,
    24898,	23567,	24765,	24346,	25966,	24652,	24954,	25333,	27487,	26644,
    26136,	25891,	26038,	25391,	24475,	25680,	28987,	26890,	25573,	24680,
    16570,	33923,	24882,	20958,	20166,	25506,	22515,	25236,	21431,	22143,
    24737,	24024,	27606,	26139,	23549,	23334,	26079,	28095,	28946,	29768,
    29848,	31312,	31573,	31256,	29727,	32398,	34128,	30880,	35847,	31239,
    36534,	38048,	41573,	50263,	48334,	44396,	47738,	46497,	57139,	61498,
    186560,	41680,	48173,	39611,	39122,	37449,	43130,	45281,	51980,	43839,
    44601,	42473,	47284,	44962,	47340,	49996,	47783,	55460,	45404,	46914,
    47625,	54124,	35531,	46038,	43008,	40684,	45179,	45435,	43597,	38346,
    38170,	37339,	39833,	38332,	40379,	32157,	20606,	24500,	23644,	28795,
    25830,	24025,	24499,	39453,	31761,	32134,	33709,	30138,	38658,	33409,
    33364,	37063,	33540,	39082,	32640,	36665,	35588,	34639,	34574,	34371,
    33917,	34836,	32132,	34210,	32146,	33564,	34057,	34483,	33948,	39266,
    38188,	41919,	39484,	41286,	40523,	41263,	41184,	39216,	41731,	39476,
    37742,	37878,	41017,	42105,	40426,	38965,	41270,	41855,	37662,	38685,
    38790,	41713,	39844,	39257,	35159,	37805,	38546,	38083,	34684,	32702,
    37421,	40869,	34174,	34954,	33104,	41281,	34325,	43301,	40106,	40345,
    39526,	38712,	35733,	35140,	35311,	34999,	41515,	40757,	40568,	34701,
    30537,	29253,	31035,	29510,	37561,	31419,	27550,	32937,	34653,	29348,
    24496,	23706,	21391,	19997,	28700,	23781,	28914,	25997,	26034,	22151,
    23233,	23064,	24891,	22794,	23966,	23846,	28505,	29002,	66331,	34869,
    36639,	41253,	40836,	38045,	38265,	37128,	44203,	40417,	38632,	35710,
    41584,	42156,	37983,	41446,	47146,
};


static char *m_video_file_name = NULL;
static FILE *video_fp = NULL;
static UINT8 *video_frame = NULL;

static void es_player_video_task(UINT32 para1, UINT32 para2)
{
    ali_video_config *dec_config = (ali_video_config *)para1;
    unsigned long long file_size;
	RET_CODE ret = RET_SUCCESS;
    UINT32 i = 0, free_size = 0, valid_size = 0, total_size = 0;
    UINT32 read_size, need_read = 1;
    UINT32 packet_size;
    ali_video_decoder_status status;
    struct av_packet pkt;

    ali_sbm_info pe_info;
    MEMSET(&pe_info, 0, sizeof(ali_sbm_info));

    //fill the sbm config
	pe_info.mem_start = __MM_VIDEO_FILE_BUF_ADDR;
	pe_info.mem_size = __MM_VIDEO_FILE_BUF_LEN;

    #if (SYS_SDRAM_SIZE == 128 || SYS_SDRAM_SIZE == 64)
    // video file buffer is seperated with frame buffer
    #if (__MM_FB_TOP_ADDR > __MM_VIDEO_FILE_BUF_ADDR)
    pe_info.mem_size = __MM_FB_TOP_ADDR - __MM_VIDEO_FILE_BUF_ADDR;
    #endif
    pe_info.decoder_start = __MM_FB_BOTTOM_ADDR;
    pe_info.decv_buf_size = __MM_FB_TOP_ADDR - __MM_FB_BOTTOM_ADDR;
    #endif

//h.264
    dec_config->codec_tag = h264;
    dec_config->extradata = NULL;
    dec_config->extradata_size = 0;
    dec_config->frame_rate = 25000; /* param parser from container */
    dec_config->width = 1280;
    dec_config->height = 800;
    dec_config->sample_aspect_ratio.num = 1;
    dec_config->sample_aspect_ratio.den = 1;
    dec_config->preview = 0;

    if(dec_config->preview) {
        dec_config->src_rect.x = 32;
    	dec_config->src_rect.y = 96;
    	dec_config->src_rect.w = 656;
    	dec_config->src_rect.h = 2688;
    	dec_config->dst_rect.x = 430;
    	dec_config->dst_rect.y = 475;
    	dec_config->dst_rect.w = 165;
    	dec_config->dst_rect.h = 710;
    }
    m_video_file_name = NULL;

    if(m_video_file_name == NULL) {
       m_video_file_name = "/mnt/uda1/es_player/AWindH264.mp4";
    }

    MEMSET(&pkt, 0, sizeof(pkt));

    video_fp = fopen(m_video_file_name, "rb");
    if(video_fp == NULL) {
		libc_printf("Open file %s fail\n", m_video_file_name);
		return -1;
	}

    fseek(video_fp, 0, SEEK_END);
	file_size = ftell(video_fp);
	fseek(video_fp, 0, SEEK_SET);
	if(file_size <= 0) {
		libc_printf("File size error %lld\n", file_size);
		return -1;
	}

	//fflush(fp);
    libc_printf("File size %lld", file_size);

    video_frame = (UINT8 *)MALLOC(0x100000);
    if(video_frame == NULL) {
        libc_printf("Malloc frame buffer fail\n");
        return -1;
    }

    ret = ali_video_decoder_open(dec_config, pe_info);
    if(ret < 0) {
        libc_printf("open video decoder fail\n");
        return -1;
    }

    ali_video_decoder_set_sync(dec_config, FALSE); //video free run, don't avsync

    ret = ali_sbm_show_total_size(VPKT_DATA_SBM_IDX, &total_size);
    if(ret < 0){
        libc_printf("sbm ioctl fail\n");
    }

    while(1) {
        ret = ali_sbm_show_free_size(VPKT_DATA_SBM_IDX, &free_size);
        if(ret < 0){
            libc_printf("sbm ioctl fail\n");
        }

        ret = ali_sbm_show_valid_size(VPKT_DATA_SBM_IDX, &valid_size);
        if(ret < 0){
            libc_printf("sbm ioctl fail\n");
        }

        if(dec_config->extradata_size > 0 && dec_config->extradata)
        {
            dec_config->extradata = NULL;
            i++;
        }

        if(need_read) {
            /* parse a complete frame */
          read_size = fread(video_frame, 1, frame_size[i], video_fp);
          packet_size = frame_size[i];

        }

        if(read_size == packet_size)
        {
            if(free_size > read_size && valid_size < total_size*4/5)
            {
                pkt.pts = AV_NOPTS_VALUE;
                pkt.dts = AV_NOPTS_VALUE;
                pkt.size = read_size;
                ret = ali_video_decoder_write_header(&pkt);
                if(ret == 0)
                {
                   do {
                        ret = ali_video_decoder_write(video_frame, read_size);

                        if(ret < 0) {
                            libc_printf("Write video packet data fail\n");
                            osal_task_sleep(10);
                        }
                    } while (ret < 0);
                }
                else
                {
                    libc_printf("Write video packet header fail\n");
                    goto sleep;
                }

                if(++i >= ARRAY_SIZE(frame_size))
                    break;

                need_read = 1;
            }
            else
            {
                ali_video_decoder_get_status(dec_config, &status);
                //libc_printf("video decoder status, width: %d, height: %d \n", status.width, status.height);
                need_read = 0;
            }
        }
        else
        {
            if(valid_size <= 1024)
            {
                libc_printf("Read video frame error %d %d\n", read_size, frame_size[i]);
                goto task_exit;
            }
        }
sleep:
       osal_task_sleep(5);
    }

task_exit:
    ali_video_decoder_close(dec_config);

	fclose(video_fp);
    video_fp = NULL;
    FREE(video_frame);
    video_frame = NULL;

    libc_printf("=====Exit playing file %s=====", m_video_file_name);
}

RET_CODE win_es_player_video_init(ali_video_config * dec_config, OSAL_ID	tsk_id)
{
    OSAL_T_CTSK t_ctsk;

    //create es player task
	t_ctsk.itskpri = OSAL_PRI_HIGH;
	t_ctsk.stksz = 0x4000;
	t_ctsk.quantum = 10;
	t_ctsk.name[0] = 'e';
	t_ctsk.name[1] = 's';
	t_ctsk.name[2] = 'p';
    t_ctsk.para1 = (UINT32)dec_config;
	t_ctsk.task = es_player_video_task;
	*(UINT32 *)tsk_id = osal_task_create(&t_ctsk);
	if(OSAL_INVALID_ID == *(UINT32 *)tsk_id)
	{
		return -1;
	}
}

RET_CODE win_es_player_video_close(ali_video_config * dec_config, OSAL_ID	tsk_id)
{

	if(OSAL_INVALID_ID != tsk_id)
	{
        ali_video_decoder_close(dec_config);
		osal_task_delete(tsk_id);
	}

    if(video_fp != NULL)
    {
        fclose(video_fp);
        video_fp = NULL;
    }

    if(video_frame != NULL)
    {
        FREE(video_frame);
        video_frame = NULL;
    }

}

static UINT32 audio_frame_size[] =
{
    17,20,10,10,38,65,31,30,139,31,31,31,31,31,31,31,31,31,31,31,31,31,
    31,31,31,31,31,31,31,31,31,108,613,557,451,465,455,459,465,459,472,462,
    467,467,471,487,465,462,476,478,483,485,437,438,456,458,460,479,387,416,
    475,482,491,474,605,477,469,451,440,442,442,455,465,464,469,448,466,476,
    483,490,492,475,474,489,478,482,464,475,443,464,604,466,467,470,444,444,
    437,472,498,502,503,494,505,507,515,493,482,567,456,475,439,463,465,467,
    491,510,509,507,487,483,495,489,491,498,477,464,446,480,511,526,529,481,
    480,474,472,478,463,494,509,518,477,456,482,505,512,491,490,497,508,477,
    478,489,506,514,511,480,472,474,487,502,501,489,482,473,486,511,514,526,
    525,481,462,451,450,495,493,507,476,487,487,466,475,481,493,479,480,483,
    483,477,501,491,512,516,460,480,485,480,500,465,445,441,499,503,518,494,
    510,496,496,495,492,484,492,493,499,503,501,506,504,495,498,508,499,488,
    500,481,488,483,479,496,514,467,461,468,466,466,475,470,470,461,482,480,
    482,523,484,486,480,467,474,477,487,441,469,483,487,482,475,481,505,499,
    491,481,486,498,502,500,496,494,503,502,501,507,494,491,487,481,478,486,
    489,486,496,498,483,489,489,480,478,469,478,471,479,484,466,462,492,475,
    475,464,454,483,493,503,494,510,467,460,474,494,489,492,486,480,484,480,
    471,470,490,579,563,462,486,461,463,478,484,473,433,434,452,474,455,467,
    465,464,463,462,492,491,499,493,585,481,493,472,484,502,493,507,496,487,
    480,485,476,476,478,472,476,473,477,477,479,483,483,479,477,467,454,453,
    457,487,513,523,530,540,481,481,477,476,456,437,447,485,499,502,500,498,
    501,492,492,502,490,492,493,475,487,478,473,484,479,476,465,451,468,484,
    488,496,507,495,506,493,484,471,473,487,493,491,510,518,517,523,491,495,
    496,476,469,477,491,478,481,488,474,427,423,492,621,597,469,481,399,441,
    456,488,500,485,489,488,489,481,482,474,448,474,487,515,502,474,475,483,
    476,458,436,462,478,493,487,501,598,493,478,471,476,465,465,478,467,455,
    475,468,578,453,472,471,453,469,484,487,468,465,448,445,473,494,504,505,
    503,525,511,495,499,488,486,471,488,478,475,483,469,490,479,467,479,467,
    472,470,475,479,508,506,486,477,474,472,482,475,451,473,482,464,480,463,
    455,483,577,461,483,463,464,496,503,502,494,438,469,486,492,494,475,489,
    477,491,478,487,479,497,592,490,488,501,482,493,493,486,458,435,428,487,
    482,488,494,522,513,493,488,476,481,493,480,474,444,452,475,497,496,630,
    470,475,447,446,477,465,490,498,499,493,480,480,479,486,490,495,483,481,
    467,486,479,479,467,618,481,486,471,479,482,470,463,468,479,480,495,485,
    510,488,475,494,511,516,516,483,476,461,460,455,473,495,508,500,507,505,
    503,488,491,479,489,502,493,492,494,483,486,483,476,597,506,508,504,505,
    497,634,479,439,434,443,443,438,413,414,428,438,483,511,508,493,507,502,
    483,486,495,491,473,480,456,497,545,528,532,481,488,475,467,458,452,466,
    499,499,498,499,500,491,495,497,498,510,495,495,467,433,470,462,487,505,
    498,482,496,488,492,506,483,487,438,456,487,487,505,513,500,487,479,478,
    503,504,496,493,515,544,488,483,485,488,480,489,475,433,425,491,500,535,
    494,474,443,473,479,443,455,602,497,499,493,487,485,482,484,497,498,499,
    496,485,483,479,468,479,466,489,506,491,510,516,499,406,410,415,405,404,
    426,427,430,450,470,488,490,505,508,490,485,486,485,502,485,492,493,613,
    591,479,481,487,481,480,466,456,453,431,472,483,492,495,485,496,463,481,
    473,443,499,582,496,494,471,479,504,478,482,455,438,428,383,439,606,482,
    486,472,455,449,457,456,470,470,583,587,475,480,451,469,511,500,475,471,
    445,438,468,497,502,493,462,409,399,425,458,482,487,476,469,473,475,463,
    488,480,484,484,487,479,471,480,496,498,494,471,467,473,473,483,478,465,
    438,451,487,597,480,486,467,481,474,481,490,480,479,468,461,464,486,498,
    531,533,497,437,457,452,458,487,498,469,466,467,481,474,464,468,484,479,
    436,417,479,505,509,526,477,481,471,470,469,465,482,476,483,492,487,478,
    479,481,485,470,466,489,496,498,490,492,497,489,502,489,496,502,492,489,
    483,472,485,492,496,472,489,488,464,471,476,485,470,480,591,475,474,473,
    482,473,480,470,595,463,462,448,469,465,461,573,446,447,434,446,446,460,
    534,461,447,409,435,444,436,459,548,459,464,452,443,470,597,611,515,514,
    482,483,469,448,629,593,516,501,454,473,484,477,630,519,510,510,515,499,
    506,512,512,512,505,521,520,509,511,509,503,493,510,509,499,493,511,514,
    506,500,509,507,506,493,620,512,513,508,510,502,513,507,497,511,507,502,
    494,503,498,498,493,499,500,498,501,498,504,494,499,497,495,502,491,498,
    485,476,495,509,495,506,498,515,501,501,506,493,497,493,485,484,488,480,
    485,501,491,499,485,492,483,473,479,472,464,485,507,496,492,483,474,474,
    480,470,472,476,486,477,473,583,621,512,492,464,483,481,476,477,480,489,
    495,482,488,493,603,631,515,514,486,474,490,603,475,481,453,433,453,470,
    463,625,504,487,501,518,477,471,471,452,425,455,487,478,502,502,507,523,
    503,517,503,512,518,501,502,514,506,500,492,504,512,508,506,499,504,502,
    501,513,508,510,511,506,505,504,506,504,517,516,505,497,503,505,507,516,
    517,508,507,511,511,514,512,507,510,498,492,492,510,503,511,501,495,479,
    495,510,492,491,496,484,463,475,492,485,493,475,479,455,430,478,483,491,
    629,513,516,509,498,500,496,483,486,494,496,502,501,496,511,497,494,483,
    499,513,499,500,624,507,510,500,510,504,505,510,603,504,496,494,488,496,
    498,494,481,478,499,518,483,463,478,462,474,514,507,511,512,510,510,506,
    500,503,511,503,497,507,514,508,503,498,505,502,503,497,496,502,496,502,
    504,508,509,514,517,497,483,497,500,501,492,500,508,513,514,512,498,483,
    506,489,491,491,506,512,505,506,495,509,507,508,503,505,615,504,514,478,
    473,481,487,496,493,500,507,482,472,480,481,484,513,513,502,487,492,498,
    617,495,481,472,472,481,480,488,519,518,498,496,490,491,494,501,496,499,
    496,489,484,464,611,508,498,475,489,479,494,497,495,491,496,502,506,510,
    499,587,509,512,493,495,496,500,506,507,502,497,485,479,477,620,637,526,
    522,510,487,492,491,600,479,476,479,481,467,482,514,532,494,495,491,486,
    499,500,509,503,506,485,500,506,491,588,511,517,483,498,497,498,512,635,
    521,517,496,507,515,499,603,500,504,480,483,488,498,510,505,497,486,504,
    508,509,518,622,608,522,523,502,482,485,623,595,474,483,475,480,475,503,
    510,529,510,503,493,499,495,502,510,508,502,507,508,513,628,628,515,508,
    506,517,504,506,515,501,504,491,482,482,494,492,467,475,482,513,514,520,
    512,515,506,517,512,507,506,510,505,482,473,494,504,516,510,511,503,521,
    508,516,508,514,521,508,504,506,516,506,506,506,503,506,489,491,498,508,
    513,625,568,489,486,486,488,500,486,595,513,517,506,508,488,507,508,517,
    512,510,509,492,500,503,611,498,492,483,489,494,490,495,613,505,491,475,
    481,500,494,481,465,473,470,446,475,499,602,466,472,475,464,459,481,497,
    487,491,478,481,495,480,496,492,439,444,464,494,495,472,493,492,480,479,
    491,494,505,605,596,511,515,510,511,500,498,507,505,510,507,490,469,465,
    502,494,502,508,507,505,511,508,504,497,504,499,496,498,499,499,501,508,
    490,493,504,497,517,497,488,494,501,488,493,515,505,491,496,499,484,514,
    499,501,497,495,486,502,498,504,485,610,607,495,493,472,492,506,489,478,
    496,501,499,484,484,488,495,506,503,501,498,491,497,493,486,495,504,488,
    487,479,481,497,513,511,504,494,484,465,580,486,463,476,468,609,600,477,
    472,580,475,477,475,471,480,485,482,482,453,446,471,603,592,491,514,514,
    522,514,514,506,511,504,508,507,501,513,509,498,520,509,502,517,518,501,
    511,512,501,486,490,498,490,501,509,511,520,510,504,517,504,511,515,508,
    517,503,510,519,503,504,502,504,516,510,506,510,514,
};

static char *m_audio_file_name = NULL;
static FILE *audio_fp = NULL;
static UINT8 *audio_frame = NULL;

static void es_player_audio_task(UINT32 para1, UINT32 para2)
{
    ali_audio_config *dec_config = (ali_audio_config *)para1;
    unsigned long long file_size;
	RET_CODE ret = RET_SUCCESS;
    UINT32 i = 0, free_size = 0, valid_size = 0, total_size = 0;
    UINT32 read_size, need_read = 1;
    struct av_packet pkt;

    ali_sbm_info pe_info;
    MEMSET(&pe_info, 0, sizeof(ali_sbm_info));

    //fill the sbm config
	pe_info.mem_start = __MM_VIDEO_FILE_BUF_ADDR;
	pe_info.mem_size = __MM_VIDEO_FILE_BUF_LEN;

    #if (SYS_SDRAM_SIZE == 128 || SYS_SDRAM_SIZE == 64)
    // video file buffer is seperated with frame buffer
    #if (__MM_FB_TOP_ADDR > __MM_VIDEO_FILE_BUF_ADDR)
    pe_info.mem_size = __MM_FB_TOP_ADDR - __MM_VIDEO_FILE_BUF_ADDR;
    #endif
    pe_info.decoder_start = __MM_FB_BOTTOM_ADDR;
    pe_info.decv_buf_size = __MM_FB_TOP_ADDR - __MM_FB_BOTTOM_ADDR;
    #endif

    dec_config->codec_id = 0x15002;
    dec_config->av_sync_mode = 1;
    dec_config->av_sync_unit = 0;
    dec_config->bits_per_coded_sample = 32;
    dec_config->sample_rate = 48000;
    dec_config->channels = 2;
    dec_config->bit_rate = 0;

    m_audio_file_name = NULL;

    if(m_audio_file_name == NULL) {
        m_audio_file_name = "/mnt/uda1/es_player/Test_48000.dat";
    }

    MEMSET(&pkt, 0, sizeof(pkt));

    audio_fp = fopen(m_audio_file_name, "rb");
    if(audio_fp == NULL) {
		libc_printf("Open file %s fail\n", m_audio_file_name);
		return -1;
	}

    fseek(audio_fp, 0, SEEK_END);
	file_size = ftell(audio_fp);
	fseek(audio_fp, 0, SEEK_SET);
	if(file_size <= 0) {
		libc_printf("File size error %lld\n", file_size);
		return -1;
	}

	//fflush(fp);
    libc_printf("File size %lld", file_size);

    audio_frame = (UINT8 *)MALLOC(0x100000);
    if(audio_frame == NULL) {
        libc_printf("Malloc frame buffer fail\n");
        return -1;
    }

    ret = ali_audio_decoder_open(dec_config, pe_info);
    if(ret < 0) {
        libc_printf("open audio decoder fail\n");
        return -1;
    }

    ret = ali_sbm_show_total_size(APKT_DATA_SBM_IDX, &total_size);
    if(ret < 0){
        libc_printf("sbm ioctl fail\n");
    }

    while(1) {
        ret = ali_sbm_show_free_size(APKT_DATA_SBM_IDX, &free_size);
        if(ret < 0) {
            libc_printf("sbm ioctl fail\n");
        }

        ret = ali_sbm_show_valid_size(APKT_DATA_SBM_IDX, &valid_size);
        if(ret < 0) {
            libc_printf("sbm ioctl fail\n");
        }

        if(need_read) {
            /* parse a complete frame */
            read_size = fread(audio_frame, 1, audio_frame_size[i], audio_fp);
        }

        if(read_size == audio_frame_size[i]) {
            if(free_size > read_size && valid_size < total_size*4/5) {
                pkt.pts = AV_NOPTS_VALUE;
                pkt.dts = AV_NOPTS_VALUE;
                pkt.size = read_size;

                if(i == 0) {
                    UINT32 base_time = (pkt.pts==AV_NOPTS_VALUE)?0:pkt.pts;
                    ret = ali_audio_decore_ioctl(dec_config, DECA_DECORE_SET_BASE_TIME, &base_time, &base_time);
                    if(ret < 0) {
                        libc_printf("deca decore set base time fail\n");
                    }
                }

                ret = ali_audio_decoder_write_header(&pkt);
                if(ret == 0) {
                    do {
                        ret = ali_audio_decoder_write(audio_frame, read_size);

                        if(ret < 0) {
                            libc_printf("Write audio packet data fail\n");
                            osal_task_sleep(10);
                        }
                    } while (ret < 0);

                } else {
                    libc_printf("Write audio packet header fail\n");
                    goto sleep;
                }

                if(++i >= ARRAY_SIZE(audio_frame_size))
                    break;

                need_read = 1;
            }
            else
            {
                need_read = 0;
            }
        }
        else
        {
            if(valid_size <= 1024)
            {
                libc_printf("Read audio frame error %d %d\n", read_size, audio_frame_size[i]);
                goto task_exit;
            }
        }
sleep:
       osal_task_sleep(5);
    }

task_exit:
    ali_audio_decoder_close(dec_config);

	fclose(audio_fp);
    audio_fp = NULL;
    FREE(audio_frame);
    audio_frame = NULL;

    libc_printf("=====Exit playing file %s=====", m_audio_file_name);
}

RET_CODE win_es_player_audio_init(ali_audio_config *dec_config, OSAL_ID	tsk_id)
{
    OSAL_T_CTSK t_ctsk;

    //create es player task
	t_ctsk.itskpri = OSAL_PRI_HIGH;
	t_ctsk.stksz = 0x4000;
	t_ctsk.quantum = 10;
	t_ctsk.name[0] = 'e';
	t_ctsk.name[1] = 's';
	t_ctsk.name[2] = 'p';
    t_ctsk.para1 = (UINT32)dec_config;
	t_ctsk.task = es_player_audio_task;
	*(UINT32 *)tsk_id = osal_task_create(&t_ctsk);
	if(OSAL_INVALID_ID == *(UINT32 *)tsk_id)
	{
		return -1;
	}
}

RET_CODE win_es_player_audio_close(ali_audio_config * dec_config, OSAL_ID	tsk_id)
{

	if(OSAL_INVALID_ID != tsk_id)
	{
        ali_audio_decoder_close(dec_config);
		osal_task_delete(tsk_id);
	}

    if(audio_fp != NULL)
    {
        fclose(audio_fp);
        audio_fp = NULL;
    }

    if(audio_frame != NULL)
    {
        FREE(audio_frame);
        audio_frame = NULL;
    }

}
/*****************************************end********************************/
#endif

void file_list_init_parameter()
{
//	mp_udisk_cnt = get_stroage_device_number(STORAGE_TYPE_ALL);
#ifdef DVR_PVR_SUPPORT
//	udisk_set_ingore_dir(PVR_ROOT_DIR);
#endif
//	playlist_readfromdisk(MP_MUSIC);
//	playlist_readfromdisk(MP_PICTURE);
	init_usblist_param();
//	MEMSET(m_mp_last_access_device, 0xff, sizeof(m_mp_last_access_device));
}


BOOL win_check_del_flag(UINT32 *pdel_array, UINT32 index)
{
	UINT32	wIndex;
	UINT8	bShiftBit;

	wIndex		= index/32;
	bShiftBit	= (UINT8)(index%32);

	if((pdel_array[wIndex])&(0x00000001<<bShiftBit))
		return TRUE;
	else
		return FALSE;
}

BOOL win_check_del_flags(UINT32 *pdel_array, UINT32 array_size)
{
	OBJLIST* ol;
	UINT32 i,n;

	n = array_size/32;	/* current playlist totoa number */

	for(i=0;i<n;i++)
		if(pdel_array[i]>0)	return TRUE;

	for(i=n*32; i< array_size; i++)
		if(win_check_del_flag(pdel_array, i))
			return TRUE;

	return FALSE;
}

void win_switch_del_flag(UINT32 *pdel_array, UINT32 index)
{
	UINT32	wIndex;
	UINT8	bShiftBit;

	wIndex		= index/32;
	bShiftBit	= index%32;
	pdel_array[wIndex] ^= (0x00000001<<bShiftBit);
}

void win_clear_del_flags(UINT32 *pdel_array, UINT32 array_size)
{
	UINT32 i,n;

	n = array_size/sizeof(pdel_array[0]);
	for(i=0;i<n;i++)
		pdel_array[i] = 0;
}

void win_set_del_flags(UINT32 *pdel_array, UINT32 array_size)
{
	UINT32 i,n;

	n = array_size/sizeof(pdel_array[0]);
	for(i=0;i<n;i++)
		pdel_array[i] = (UINT32)(~0);
}

#endif

